Ejemplo n.º 1
0
// Daemon will run and maintain skynet services.
//
// Daemon will run the "SkynetDeployment" service, which can be used
// to remotely spawn new services on the host.
func main() {
	config, _ := skynet.GetServiceConfig()
	log.Println(log.INFO, "Connecting to ZooKeeper: ", os.Getenv("SKYNET_ZOOKEEPER"))
	skynet.SetServiceManager(zkmanager.NewZookeeperServiceManager(os.Getenv("SKYNET_ZOOKEEPER"), 1*time.Second))

	config.Name = "SkynetDaemon"
	config.Version = "2"

	deployment := NewSkynetDaemon()

	s := service.CreateService(deployment, config)

	deployment.Service = s

	// handle panic so that we remove ourselves from the pool in case of catastrophic failure
	defer func() {
		s.Shutdown()
		deployment.closeStateFile()

		if err := recover(); err != nil {
			e := err.(error)
			log.Fatal("Unrecovered error occured: " + e.Error())
		}
	}()

	// Collect Host metrics
	statTicker := time.Tick((5 * time.Second))
	go func() {
		for _ = range statTicker {
			deployment.updateHostStats(config.ServiceAddr.IPAddress)
		}
	}()

	// If we pass false here service will not be Registered
	// we could do other work/tasks by implementing the Started method and calling Register() when we're ready
	s.Start().Wait()
}
Ejemplo n.º 2
0
func GetRegions() []string {
	sm := zkmanager.NewZookeeperServiceManager("localhost:2181", 1*time.Second)
	return sm.ListRegions(skynet.ServiceQuery{})
}
Ejemplo n.º 3
0
func GetInstances() []skynet.ServiceInfo {
	sm := zkmanager.NewZookeeperServiceManager("localhost:2181", 1*time.Second)
	return sm.ListInstances(skynet.ServiceQuery{})
}
Ejemplo n.º 4
0
func main() {
	// TODO: We need to timeout here, if no zookeeper is up it just hangs
	skynet.SetServiceManager(zkmanager.NewZookeeperServiceManager(os.Getenv("SKYNET_ZOOKEEPER"), 1*time.Second))
	var args []string
	Config, args = skynet.GetClientConfigFromFlags(os.Args)
	Config.MaxConnectionsToInstance = 10
	Client = client.NewClient(Config)
	criteria, args := criteriaFromArgs(args)

	args = args[1:]

	if len(args) == 0 {
		CommandLineHelp()
		return
	}

	switch args[0] {
	case "help", "h":
		CommandLineHelp()
	case "build", "b":
		flagset := flag.NewFlagSet("build", flag.ExitOnError)
		config := flagset.String("config", "./build.cfg", "build config file")
		flagsetArgs, _ := skynet.SplitFlagsetFromArgs(flagset, args)

		err := flagset.Parse(flagsetArgs)
		if err != nil {
			panic(err)
			return
		}

		Build(*config)
	case "deploy", "d":
		flagset := flag.NewFlagSet("deploy", flag.ExitOnError)
		config := flagset.String("config", "./build.cfg", "build config file")
		flagsetArgs, _ := skynet.SplitFlagsetFromArgs(flagset, args)

		err := flagset.Parse(flagsetArgs)
		if err != nil {
			panic(err)
			return
		}

		Deploy(*config, criteria)
	case "hosts":
		ListHosts(criteria)
	case "regions":
		ListRegions(criteria)
	case "services":
		ListServices(criteria)
	case "versions":
		ListVersions(criteria)
	case "instances":
		ListInstances(criteria)
	case "start":
		Start(criteria, args[1:])
	case "stop":
		Stop(criteria)
	case "restart":
		Restart(criteria)
	case "register":
		Register(criteria)
	case "unregister":
		Unregister(criteria)
	case "log":
		SetLogLevel(criteria, args[1])
	case "daemon":
		if len(args) >= 2 {
			switch args[1] {
			case "log":
				if len(args) >= 3 {
					SetDaemonLogLevel(criteria, args[2])
				} else {
					fmt.Println("Must supply a log level")
				}
			case "stop":
				StopDaemon(criteria)
			}
		} else {
			fmt.Println("Supported subcommands for daemon are log, and stop")
		}
	case "cli":
		InteractiveShell()
	default:
		fmt.Println("Unknown Command: ", args[0])
		CommandLineHelp()
	}
}