Ejemplo n.º 1
0
func main() {
	testService := NewTestService()

	config := skylib.GetServiceConfigFromFlags()
	config.Name = "TestService"
	config.Version = "1"
	config.Region = "Clearwater"
	var err error
	mlogger, err := skylib.NewMongoLogger("localhost", "skynet", "log", config)
	clogger := skylib.NewConsoleLogger(os.Stdout)
	config.Log = skylib.NewMultiLogger(mlogger, clogger)
	if err != nil {
		config.Log.Item("Could not connect to mongo db for logging")
	}
	service := skylib.CreateService(testService, config)

	// handle panic so that we remove ourselves from the pool in case of catastrophic failure
	defer func() {
		service.Shutdown()
		if err := recover(); err != nil {
			log.Println("Unrecovered error occured: ", err)
		}
	}()

	// 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
	service.Start(true)
}
Ejemplo n.º 2
0
// Daemon() will run and maintain skynet services.
//
// Daemon() will initially deploy those specified in the file given in the "-config" option
//
// Daemon() will run the "SkynetDeployment" service, which can be used to remotely spawn
// new services on the host.
func Daemon(q *skylib.Query, argv []string) {

	config, args := skylib.GetServiceConfigFromFlags(argv...)
	config.Name = "SkynetDaemon"
	config.Version = "1"
	config.Region = "Jersey"

	var err error
	mlogger, err := skylib.NewMongoLogger("localhost", "skynet", "log", config)
	clogger := skylib.NewConsoleLogger(os.Stdout)
	config.Log = skylib.NewMultiLogger(mlogger, clogger)
	if err != nil {
		config.Log.Item("Could not connect to mongo db for logging")
	}

	deployment := &SkynetDaemon{
		Log:      config.Log,
		Services: map[string]*SubService{},
	}

	service := skylib.CreateService(deployment, config)

	// handle panic so that we remove ourselves from the pool in case of catastrophic failure
	defer func() {
		service.Shutdown()
		if err := recover(); err != nil {
			log.Println("Unrecovered error occured: ", err)
		}
	}()

	if len(args) == 2 {
		err := deployConfig(deployment, args[0])
		if err != nil {
			config.Log.Item(err)
		}
	}

	// 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
	service.Start(true)
}