示例#1
0
func main() {
	var err error

	flag.Parse()

	log = skynet.NewConsoleSemanticLogger("dashboard", os.Stderr)
	if *mgoserver == "" {
		log.Trace(fmt.Sprintf("%+v", skynet.MongoError{
			"",
			"No mongodb server url (both -mgoserver and SKYNET_MGOSERVER missing)",
		}))
	}

	mlogger, err := skynet.NewMongoSemanticLogger(*mgoserver, "skynet",
		"log", skynet.UUID())
	if err != nil {
		log.Error(fmt.Sprintf("%+v", skynet.MongoError{
			Addr: "Could not connect to mongo db for logging",
			Err:  err.Error(),
		}))
	}
	log = skynet.NewMultiSemanticLogger(mlogger, log)

	DC = Doozer()

	http.HandleFunc("/", indexHandler)
	http.HandleFunc("/logs/search", searchHandler)
	http.Handle("/media/", http.StripPrefix("/media/", http.FileServer(http.Dir(*webroot+"/tmpl"))))
	http.Handle("/favicon.ico", http.FileServer(http.Dir(*webroot+"/tmpl/images")))
	http.Handle("/logs/ws", websocket.Handler(wsHandler))

	im := client.NewInstanceMonitor(DC, true)
	http.Handle("/instances/ws", websocket.Handler(func(ws *websocket.Conn) {
		NewInstanceSocket(ws, im)
	}))

	// Cache templates
	layoutTmpl = template.Must(template.ParseFiles(*webroot +
		"/tmpl/layout.html.template"))
	indexTmpl = template.Must(template.ParseFiles(*webroot +
		"/tmpl/index.html.template"))
	searchTmpl = template.Must(template.ParseFiles(*webroot +
		"/tmpl/search.html.template"))

	err = http.ListenAndServe(*addr, nil)
	if err != nil {
		log.Fatal("ListenAndServe: " + err.Error())
	}
}
示例#2
0
文件: service.go 项目: arjloo/skynet
func main() {
	testService := NewTestService()

	config, _ := skynet.GetServiceConfig()

	if config.Name == "" {
		config.Name = "TestService"
	}

	if config.Version == "" {
		config.Version = "1"
	}

	if config.Region == "unknown" {
		config.Region = "Clearwater"
	}

	var err error
	mlogger, err := skynet.NewMongoSemanticLogger("localhost", "skynet",
		"log", config.UUID)
	clogger := skynet.NewConsoleSemanticLogger("TestService", os.Stdout)
	testService.Log = skynet.NewMultiSemanticLogger(mlogger, clogger)
	config.Log = testService.Log
	if err != nil {
		config.Log.Trace("Could not connect to mongo db for logging")
	}
	service := service.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
	waiter := service.Start(true)

	// waiting on the sync.WaitGroup returned by service.Start() will
	// wait for the service to finish running.
	waiter.Wait()
}
示例#3
0
文件: main.go 项目: arjloo/skynet
// 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 main() {
	config, args := skynet.GetServiceConfig()

	config.Name = "SkynetDaemon"
	config.Version = "1"

	// skydaemon does not listen to admin RPC requests
	config.AdminAddr = nil

	var err error
	mlogger, err := skynet.NewMongoSemanticLogger(config.MongoConfig.MongoHosts, "skynet",
		"log", config.UUID)
	clogger := skynet.NewConsoleSemanticLogger("skydaemon", os.Stdout)
	config.Log = skynet.NewMultiSemanticLogger(mlogger, clogger)
	if err != nil {
		config.Log.Trace("Could not connect to mongo db for logging")
	}

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

	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()
		if err := recover(); err != nil {
			log.Println("Unrecovered error occured: ", err)
		}
	}()*/

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

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