Example #1
0
func main() {
	var err error
	flags.Parse(os.Args[1:])

	conf, err := server.NewConfigFromFile(*confFile, os.Getenv("CONFIG"))
	if err != nil {
		log.Fatal(err)
	}

	srv := server.New(conf)
	if err := srv.Configure(); err != nil {
		log.Fatal(err)
	}

	lg.Infof("** Imgry Server v%s at %s **", imgry.VERSION, srv.Config.Bind)
	lg.Infof("** Engine: %s", srv.ImageEngine.Version())

	graceful.AddSignal(syscall.SIGINT, syscall.SIGTERM)
	graceful.Timeout(30 * time.Second)
	graceful.PreHook(srv.Close)
	graceful.PostHook(srv.Shutdown)

	err = graceful.ListenAndServe(srv.Config.Bind, srv.NewRouter())
	if err != nil {
		lg.Fatal(err.Error())
	}
	graceful.Wait()
}
Example #2
0
func main() {
	appCfg, srvCfg, err := readConfiguration()
	if err != nil {
		log.Fatalf("Error parsing configuration. event=config_error error=%q", err)
	}

	a, err := app.New(appCfg)
	if err != nil {
		log.Fatalf("Error initializing app event=init_error error=%q", err)
	}
	defer a.Close()

	listener, err := net.Listen("tcp", srvCfg.HTTPAddr)
	if err != nil {
		log.Fatalf("Error attempting to listen on port, event=listen_error address=%q error=%q", err, srvCfg.HTTPAddr)
	}

	graceful.Timeout(httpGrace)
	graceful.HandleSignals()
	graceful.PreHook(func() {
		log.Print("Shutting down. event=app_stop")
	})
	log.Printf("Starting. event=app_start address=%q", listener.Addr())
	bind.Ready()
	err = graceful.Serve(listener, a)
	if err != nil {
		log.Fatalf("Shutting down after a fatal error. event=fatal_error error=%q", err)
	}
}
Example #3
0
func (s *Server) HTTPServe() {
	httpSocket := bind.Socket(s.HTTPAddr)
	graceful.Timeout(10 * time.Second)
	graceful.PreHook(func() {
		s.logger.Info("Terminating HTTP listener")
	})
	graceful.HandleSignals()
	s.logger.WithField("address", s.HTTPAddr).Info("HTTP server listening")
	bind.Ready()

	if err := graceful.Serve(httpSocket, s.Handler()); err != nil {
		s.logger.WithError(err).Error("HTTP server shut down due to error")
	}
	graceful.Wait()
}