Example #1
0
File: gubled.go Project: mley/guble
func StartupService(args Args) *server.Service {
	router := server.NewPubSubRouter()
	router.SetAccessManager(server.NewAllowAllAccessManager(true))
	router.Go()
	service := server.NewService(
		args.Listen,
		CreateKVStoreBackend(args),
		CreateMessageStoreBackend(args),
		server.NewMessageEntry(router),
		router,
		server.NewAllowAllAccessManager(true))

	for _, module := range CreateModules(args) {
		service.Register(module)
	}

	if err := service.Start(); err != nil {
		guble.Err(err.Error())
		if err := service.Stop(); err != nil {
			guble.Err(err.Error())
		}
		os.Exit(1)
	}

	return service
}
Example #2
0
func StartService() *server.Service {
	accessManager := auth.NewAllowAllAccessManager(true)
	messageStore := CreateMessageStore()
	kvStore := CreateKVStore()

	var c *cluster.Cluster
	var err error
	if *config.Cluster.NodeID > 0 {
		exitIfInvalidClusterParams(*config.Cluster.NodeID, *config.Cluster.NodePort, *config.Cluster.Remotes)
		logger.Info("Starting in cluster-mode")
		c, err = cluster.New(&cluster.Config{
			ID:      *config.Cluster.NodeID,
			Port:    *config.Cluster.NodePort,
			Remotes: *config.Cluster.Remotes,
		})
		if err != nil {
			logger.WithField("err", err).Fatal("Service could not be started (cluster)")
		}
	} else {
		logger.Info("Starting in standalone-mode")
	}

	router := server.NewRouter(accessManager, messageStore, kvStore, c)
	webserver := webserver.New(*config.HttpListen)

	service := server.NewService(router, webserver).
		HealthEndpoint(*config.HealthEndpoint).
		MetricsEndpoint(*config.Metrics.Endpoint)

	service.RegisterModules(CreateModules(router)...)

	if err = service.Start(); err != nil {
		if err = service.Stop(); err != nil {
			logger.WithField("err", err).Error("Error when stopping service after Start() failed")
		}
		logger.WithField("err", err).Fatal("Service could not be started")
	}

	return service
}