Example #1
0
func installCmd() {
	cg := kmgConsole.NewCommandGroup()
	cg.AddCommandWithName("golang", installGolang)
	cg.AddCommandWithName("golang1.5", installGolang15)
	cg.AddCommandWithName("mysql", installMysql)
	cg.Main()
}
Example #2
0
func AddCommandList() {
	cmdGroup := kmgConsole.NewCommandGroup().
		AddCommand(kmgConsole.Command{
			Name:   "setAndRestart",
			Desc:   "install the service,and restart the service,uninstall and stop if need",
			Runner: setAndRestartCmd,
		}).AddCommandWithName(
		"setAndRestartV1",
		setAndRestartCmdV1,
	).AddCommand(kmgConsole.Command{
		Name:   "install",
		Desc:   "install the service",
		Runner: installCmd,
	}).AddCommand(kmgConsole.Command{
		Name:   "uninstall",
		Desc:   "uninstall the serivce",
		Runner: newNameCmd(Uninstall),
	}).AddCommand(kmgConsole.Command{
		Name:   "start",
		Desc:   "start the service",
		Runner: newNameCmd(Start),
	}).AddCommand(kmgConsole.Command{
		Name:   "stop",
		Desc:   "stop the service",
		Runner: newNameCmd(Stop),
	}).AddCommand(kmgConsole.Command{
		Name:   "restart",
		Desc:   "restart the service",
		Runner: newNameCmd(Restart),
	})
	kmgConsole.AddCommand(kmgConsole.Command{
		Name:   "Service",
		Runner: cmdGroup.Main,
	})
	kmgConsole.AddCommand(kmgConsole.Command{
		Name:   "Service.Process",
		Runner: processCmd,
		Hidden: true,
	})
	kmgConsole.AddCommandWithName("Service.RunTest", func() {
		cmd := ""
		flag.StringVar(&cmd, "c", "kmg service restart kmgServiceTest", "")
		flag.Parse()
		wg := sync.WaitGroup{}
		wg.Add(10)
		for i := 0; i < 10; i++ {
			go func() {
				kmgCmd.MustRunInBash("setsid " + cmd)
				wg.Done()
			}()
		}
		wg.Wait()
	})
	kmgConsole.AddCommandWithName("Service.TestJob", func() {
		time.Sleep(time.Second * 3)
		ServiceStartSuccess()
	})
	kmgConsole.AddCommandWithName("Service.TestJobTimeout", func() {
		time.Sleep(time.Minute * 10)
		ServiceStartSuccess()
	})
}