Пример #1
0
func StopDaemon(criteria *skynet.Criteria) {
	hosts, err := skynet.GetServiceManager().ListHosts(criteria)

	if err != nil {
		log.Fatal(err)
	}

	var wait sync.WaitGroup

	for _, host := range hosts {
		wait.Add(1)
		go func(host string) {
			d := daemon.GetDaemonForHost(host)

			in := daemon.StopRequest{}
			out, err := d.Stop(in)

			if err != nil {
				fmt.Println("Returned Error: " + err.Error())
				wait.Done()
				return
			}

			if out.Ok {
				fmt.Printf("Daemon stopped on host: %v\n", host)
			} else {
				fmt.Printf("Failed to stop daemon on host: %v\n", host)
			}

			wait.Done()
		}(host)
	}

	wait.Wait()
}
Пример #2
0
func Start(criteria *skynet.Criteria, args []string) {
	if len(args) < 1 {
		fmt.Println("Please provide a service name 'sky start binaryName'")
		return
	}

	hosts, err := skynet.GetServiceManager().ListHosts(criteria)

	if err != nil {
		log.Fatal(err)
	}

	var wait sync.WaitGroup

	for _, host := range hosts {
		wait.Add(1)
		go func(host string) {
			fmt.Println("Starting on host: " + host)
			d := daemon.GetDaemonForHost(host)

			in := daemon.StartSubServiceRequest{
				BinaryName: args[0],
				Args:       shellquote.Join(args[1:]...),
				// TODO: maybe an optional flag to change this?
				Registered: true,
			}
			out, err := d.StartSubService(in)

			if err != nil {
				fmt.Println("Returned Error: " + err.Error())
				wait.Done()
				return
			}

			startTemplate.Execute(os.Stdout, out)
			wait.Done()
		}(host)
	}

	wait.Wait()
}
Пример #3
0
func SetDaemonLogLevel(criteria *skynet.Criteria, level string) {
	hosts, err := skynet.GetServiceManager().ListHosts(criteria)

	if err != nil {
		log.Fatal(err)
	}

	var wait sync.WaitGroup

	for _, host := range hosts {
		wait.Add(1)
		go func(host string) {
			d := daemon.GetDaemonForHost(host)

			in := daemon.LogLevelRequest{
				Level: level,
			}
			out, err := d.LogLevel(in)

			if err != nil {
				fmt.Println("Returned Error: " + err.Error())
				wait.Done()
				return
			}

			if out.Ok {
				fmt.Printf("Set daemon log level to %v on host: %v\n", level, host)
			} else {
				fmt.Printf("Failed to set daemon log level to %v on host: %v\n", level, host)
			}

			wait.Done()
		}(host)
	}

	wait.Wait()
}