Beispiel #1
0
func main() {
	flag.Parse()
	err := bakapy.SetupLogging(*LOG_LEVEL)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	config, err := bakapy.ParseConfig(*CONFIG_PATH)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Configuration error: %s\n", err)
		os.Exit(1)
	}

	logger.Debug(string(config.PrettyFmt()))

	scriptPool := bakapy.NewDirectoryScriptPool(config)

	metaman := bakapy.NewMetaManClient(config.MetadataAddr, config.Secret)

	notificators := bakapy.NewNotificatorPool()
	for _, ncConfig := range config.Notificators {
		nc := bakapy.NewScriptedNotificator(scriptPool, ncConfig.Name, ncConfig.Params)
		notificators.Add(nc)
	}

	scheduler := cron.New()
	for jobName, jobConfig := range config.Jobs {
		runSpec := jobConfig.RunAt.SchedulerString()

		if jobConfig.Disabled {
			logger.Warning("job %s disabled, skipping", jobName)
			continue
		}
		storageAddr, exist := config.Storages[jobConfig.Storage]
		if !exist {
			logger.Critical("cannot find storage %s definition in config", jobConfig.Storage)
			os.Exit(1)
		}
		executor := bakapy.NewBashExecutor(jobConfig.Args, jobConfig.Host, jobConfig.Port, jobConfig.Sudo)
		job := bakapy.NewJob(
			jobName, jobConfig, storageAddr,
			scriptPool, executor, metaman,
			notificators,
		)
		logger.Info("adding job %s{%s} to scheduler", jobName, runSpec)
		err := scheduler.AddJob(runSpec, job)
		if err != nil {
			logger.Critical("cannot schedule job %s: %s", jobName, err)
			os.Exit(1)
		}
	}

	if *TEST_CONFIG_ONLY {
		return
	}

	scheduler.Start()
	<-(make(chan int))
}
Beispiel #2
0
func main() {
	flag.Parse()
	err := bakapy.SetupLogging(*LOG_LEVEL)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	config, err := bakapy.ParseConfig(*CONFIG_PATH)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
	metaman := bakapy.NewMetaManClient(config.MetadataAddr, config.Secret)
	spool := bakapy.NewDirectoryScriptPool(config)

	jobName := *JOB_NAME
	jobConfig, jobExist := config.Jobs[jobName]
	if !jobExist {
		fmt.Printf("Job %s not found\n", jobName)
		os.Exit(1)
	}

	notificators := bakapy.NewNotificatorPool()
	for _, ncConfig := range config.Notificators {
		nc := bakapy.NewScriptedNotificator(spool, ncConfig.Name, ncConfig.Params)
		notificators.Add(nc)
	}

	storageAddr, exist := config.Storages[jobConfig.Storage]
	if !exist {
		fmt.Printf("Error: cannot find storage %s definition in config\n", jobConfig.Storage)
		os.Exit(1)
	}
	executor := bakapy.NewBashExecutor(jobConfig.Args, jobConfig.Host, jobConfig.Port, jobConfig.Sudo)
	job := bakapy.NewJob(
		jobName, jobConfig, storageAddr,
		spool, executor, metaman,
		notificators,
	)
	if *FORCE_TASK_ID != "" {
		if len(*FORCE_TASK_ID) != 36 {
			fmt.Println("TaskId length must be 36 bytes")
			os.Exit(1)
		}
		job.TaskId = bakapy.TaskId(*FORCE_TASK_ID)
	}
	job.Run()

	md, err := metaman.View(job.TaskId)
	if !md.Success {
		fmt.Fprintf(os.Stderr, "job failed: %s, %s\n", md.Message, md)
		os.Exit(1)
	} else {
		fmt.Println("Job finished")
	}
}
Beispiel #3
0
func main() {
	flag.Parse()
	err := bakapy.SetupLogging(*LOG_LEVEL)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	config, err := ParseConfig(*CONFIG_PATH)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Configuration error: %s\n", err)
		os.Exit(1)
	}

	metaman := bakapy.NewMetaManClient(config.MetadataAddr, config.Secret)
	storage := NewStorage(config.Root, config.Listen, metaman)

	if *TEST_CONFIG_ONLY {
		return
	}

	if *CLEAN_ONLY {
		err := CleanupExpiredJobs(metaman, storage)
		if err != nil {
			logger.Warning("cleanup failed: %s", err.Error())
			os.Exit(1)
		}
		os.Exit(0)
	}

	storage.Start()

	done := make(chan bool)
	shutDownSigs := make(chan os.Signal, 1)
	signal.Notify(shutDownSigs, syscall.SIGINT, syscall.SIGTERM)
	go func() {
		sig := <-shutDownSigs
		logger.Warning("Got signal %s, gracefully shutting down with 1 minute timeout", sig)
		done <- storage.Shutdown(60)
	}()
	go func() {
		for {
			err := CleanupExpiredJobs(metaman, storage)
			if err != nil {
				logger.Warning("cleanup failed: %s", err.Error())
			}
			time.Sleep(time.Minute)
		}
	}()
	<-done
}
Beispiel #4
0
func main() {
	flag.Parse()
	err := bakapy.SetupLogging(*LOG_LEVEL)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	config, err := ParseConfig(*CONFIG_PATH)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Configuration error: %s\n", err)
		os.Exit(1)
	}

	if *TEST_CONFIG_ONLY {
		return
	}
	logger.Info("starting up with configuration %s", config)
	metaServer := NewJSONDirServer(config.Listen, config.Secret, config.Root)
	metaServer.Serve()
}
Beispiel #5
0
func main() {
	flag.Parse()
	if len(flag.Args()) == 0 {
		fmt.Println(USAGE)
		os.Exit(1)
	}
	if err := bakapy.SetupLogging("warning"); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	config, err := bakapy.ParseConfig(*CONFIG_PATH)
	if err != nil {
		fmt.Println("Cannot read config", err)
		os.Exit(1)
	}

	metaman := bakapy.NewMetaManClient(config.MetadataAddr, config.Secret)
	taskId := bakapy.TaskId(flag.Arg(0))

	meta, err := metaman.View(taskId)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Cannot load metadata: %s\n", err)
		os.Exit(1)
	}
	if *ONLY_KEY != "" {
		field := reflect.ValueOf(meta).FieldByName(*ONLY_KEY)
		if !field.IsValid() {
			fmt.Fprintf(os.Stderr, "Key %s not found\n", *ONLY_KEY)
			os.Exit(1)
		}
		fmt.Println(field.Interface())
	} else {
		printMetadata(meta)
	}

}