Beispiel #1
0
func realMain() error {

	flag.StringSliceVarP(&configFiles, "file", "f", nil, "file")
	flag.BoolVar(&jsonOut, "json", false, "")
	flag.BoolVarP(&versionFlag, "version", "v", false, "")

	flag.Parse()

	if jsonOut {
		logrus.SetFormatter(&logrus.JSONFormatter{})
	}

	if versionFlag {
		fmt.Printf("gcron version %s\n", VERSION)
		os.Exit(0)
	}

	c := internal.NewCron()

	if len(configFiles) == 0 {
		return errors.New("No cronfiles")
	}

	if err := loadFiles(c); err != nil {
		return err
	}

	c.Start()

	return listen(c)
}
Beispiel #2
0
func main() {
	log.SetLevel(log.FatalLevel)

	var coordinator, responseAddr, taskName string
	var taskArgs []string
	flags.StringVarP(&coordinator, "coordinator_url", "c", "", "url of the coordinator")
	flags.StringVarP(&taskName, "task", "t", "", "task to run")
	flags.StringSliceVarP(&taskArgs, "request_arg", "a", []string{}, fmt.Sprintf("task specific argument the form 'key%svalue'. can be set multiple times", argSep))
	flags.StringVarP(&responseAddr, "response_addr", "r", ":4080", "address for response http handler to listen on")
	flags.Parse()

	args, err := parseTaskArgs(taskArgs)
	dieOnError(err)

	result, stream, respErr, err := startResponseServer(responseAddr)
	dieOnError(err)

	dieOnError(makeRequest(coordinator, taskName, responseAddr, args))

	select {
	case err := <-respErr:
		dieOnError(err)
	case result := <-result:
		j, _ := json.Marshal(result)
		fmt.Println(string(j))
	case stream := <-stream:
		dieOnError(acomm.Stream(os.Stdout, stream))
	}
}
Beispiel #3
0
func init() {
	pflag.DurationVarP(&timeoutDur, "timeout", "t", 10*time.Second, "timeout for the command to complete")
	pflag.StringVarP(&username, "user", "u", "root", "user to login with")
	pflag.StringSliceVarP(&hosts, "hosts", "h", nil, "hosts to run command on")
}