Exemplo n.º 1
0
func start() {
	var (
		application app.Application
	)
	var level logging.Level
	var err error
	if level, err = logging.LogLevel(logLevel); err != nil {
		fmt.Fprintf(os.Stderr, "log level error. %s\n", err)
		fmt.Fprintf(os.Stderr, "Using default log level %s\n", DefaultLogLevel)
		level = DefaultLogLevel
	}
	// TODO: use logToStderr when deamonizing.
	if err := logger.Init("skyring", logFile, true, level); err != nil {
		panic(fmt.Sprintf("log init failed. %s", err))
	}

	conf.LoadAppConfiguration(configDir, ConfigFile)
	conf.SystemConfig.Logging.LogToStderr = logToStderr
	conf.SystemConfig.Logging.Filename = logFile
	conf.SystemConfig.Logging.Level = level
	conf.SystemConfig.Config.HttpPort = httpPort
	conf.SystemConfig.Config.SslPort = sslPort

	application = skyring.NewApp(configDir, providersDir)
	if application == nil {
		logger.Get().Fatalf("Unable to start application")
	}

	// Create router for defining the routes.
	//do not allow any routes unless defined.
	router := mux.NewRouter().StrictSlash(true)

	//Load the autheticated routes
	if err := application.SetRoutes(router); err != nil {
		logger.Get().Fatalf("Unable to create http server endpoints. error: %v", err)
	}

	// Use negroni to add middleware.  Here we add the standard
	// middlewares: Recovery, Logger and static file serve which come with
	// Negroni
	n := negroni.New(
		negroni.NewRecovery(),
		negroni.NewStatic(http.Dir(staticFileDir)),
	)
	//Add the logging context middleware
	n.Use(negroni.HandlerFunc(application.LoggingContext))

	n.UseHandler(router)

	//Initialize the application, db, auth etc
	if err := application.InitializeApplication(conf.SystemConfig, configDir); err != nil {
		logger.Get().Fatalf("Unable to initialize the application. err: %v", err)
	}

	logger.Get().Info("Starting the providers")
	//Load providers and routes
	//Load all the files present in the config path
	if err := application.StartProviders(configDir, providersDir); err != nil {
		logger.Get().Fatalf("Unable to initialize the Providers. err: %v", err)
	}

	logger.Get().Info("Starting event listener")
	go event.StartListener(SkyringEventSocketFile)

	// Starting the WebSocket server
	event.StartBroadcaster(
		websocketPort,
		conf.SystemConfig.Config.SSLEnabled,
		map[string]string{
			"cert": conf.SystemConfig.Config.SslCert,
			"key":  conf.SystemConfig.Config.SslKey,
		})

	runHTTP(
		fmt.Sprintf("%s:%d", conf.SystemConfig.Config.Host, httpPort),
		conf.SystemConfig.Config.SSLEnabled,
		fmt.Sprintf("%s:%d", conf.SystemConfig.Config.Host, sslPort),
		map[string]string{
			"cert": conf.SystemConfig.Config.SslCert,
			"key":  conf.SystemConfig.Config.SslKey,
		},
		n)

	if err := application.PostInitApplication(conf.SystemConfig); err != nil {
		logger.Get().Fatalf("Unable to run Post init. err: %v", err)
	}

	sigs := make(chan os.Signal, 1)
	done := make(chan bool, 1)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP)
	go func() {
		sig := <-sigs
		logger.Get().Info("Signal:", sig)
		done <- true
	}()
	<-done
	os.Remove(SkyringEventSocketFile)
}
Exemplo n.º 2
0
func main() {
	confStr := make([]byte, base64.StdEncoding.DecodedLen(len(os.Args[1])))
	l, _ := base64.StdEncoding.Decode(confStr, []byte(os.Args[1]))

	key, err := ioutil.ReadFile(models.SKYRING_ENC_KEY_FILE)
	if err != nil {
		panic(fmt.Sprintf("Reading enc key failed. error: %v", err))
	}
	cfgs, err := crypto.Decrypt(key, []byte(confStr[:l]))

	var config conf.SkyringCollection
	if err := json.Unmarshal(cfgs, &config); err != nil {
		panic(fmt.Sprintf("Reading configurations failed. error: %v", err))
	}
	conf.SystemConfig = config

	var eventTypes = make(map[string]string)
	if err := json.Unmarshal([]byte(os.Args[2]), &eventTypes); err != nil {
		panic(fmt.Sprintf("Reading event types failed. error: %v", err))
	}
	provider.EventTypes = eventTypes

	var providerConfig conf.ProviderInfo
	if err := json.Unmarshal([]byte(os.Args[3]), &providerConfig); err != nil {
		panic(fmt.Sprintf("Reading provider configurations failed. error: %v", err))
	}
	bigfin_conf.ProviderConfig = providerConfig

	// Initialize the logger
	level, err := logging.LogLevel(config.Logging.Level.String())
	if err != nil {
		level = logging.DEBUG
	}
	if err := logger.Init(
		"bigfin",
		fmt.Sprintf("%s/bigfin.log", filepath.Dir(config.Logging.Filename)),
		true,
		level); err != nil {
		panic(fmt.Sprintf("log init failed. %s", err))
	}

	if err := db.InitDBSession(config.DBConfig); err != nil {
		logger.Get().Fatalf("Unable to initialize DB. error: %v", err)
	}

	//Initialize the DB provider
	if err := provider.InitializeDb(); err != nil {
		logger.Get().Error("Unable to initialize the DB provider: %s", err)
	}

	// Initialize the task manager
	if err := task.InitializeTaskManager(); err != nil {
		logger.Get().Fatalf("Failed to initialize task manager. error: %v", err)
	}

	if err := provider.InitMonitoringManager(); err != nil {
		logger.Get().Fatalf("Error initializing the monitoring manager: %v", err)
	}

	if err := provider.InitInstaller(); err != nil {
		logger.Get().Fatalf("Error initializing the Installer: %v", err)
	}

	schedule.InitShechuleManager()
	if err := provider.ScheduleRbdEventEmitter(); err != nil {
		logger.Get().Error("Error while initializing RbdEventer scheduler: %v", err)
	}

	// Initialize ceph http client
	client.InitCephApiSession()

	provd := &provider.CephProvider{}
	p := pie.NewProvider()
	if err := p.RegisterName(bigfin_conf.ProviderName, provd); err != nil {
		logger.Get().Fatalf("Failed to register plugin. error: %v", err)
	}
	p.ServeCodec(jsonrpc.NewServerCodec)
}