Ejemplo n.º 1
0
func cliStartProcess(c *cli.Context) {
	args := c.Args()
	if len(args) < 1 {
		Exit("Must specify <execPath> <args...>")
	}
	execPath := args[0]
	args = args[1:]
	command := btypes.CommandStartProcess{
		Wait:     !c.Bool("bg"),
		Label:    c.String("label"),
		ExecPath: execPath,
		Args:     args,
		Input:    c.String("input"),
	}
	wg := sync.WaitGroup{}
	failed := 0
	for _, remote := range Config.Remotes {
		wg.Add(1)
		go func(remote string) {
			defer wg.Done()
			response, err := StartProcess(Config.PrivKey, remote, command)
			if err != nil {
				failed++
				fmt.Printf("%v failure. %v\n", remote, err)
			} else {
				fmt.Printf("%v success.\n", remote)
				if response.Output != "" {
					fmt.Println("--------------------------------------------------------------------------------")
					fmt.Println(response.Output)
					fmt.Println("--------------------------------------------------------------------------------")
				} else {
					fmt.Println("(no output)")
				}
			}
		}(remote)
	}
	wg.Wait()
	if 0 < failed {
		os.Exit(1)
	}
}