From 364193df4edbb466109653f731781a6744fac128 Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Sun, 4 Jul 2021 17:58:48 -0400 Subject: [PATCH] refactor some start-stop logging --- ergo.go | 4 ---- irc/server.go | 34 ++++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ergo.go b/ergo.go index 3820aef2..aa53d967 100644 --- a/ergo.go +++ b/ergo.go @@ -192,10 +192,6 @@ Options: logman.Error("server", fmt.Sprintf("Could not load server: %s", err.Error())) os.Exit(1) } - if !arguments["--quiet"].(bool) { - logman.Info("server", "Server running") - defer logman.Info("server", fmt.Sprintf("%s exiting", irc.Ver)) - } if !arguments["--smoke"].(bool) { server.Run() } diff --git a/irc/server.go b/irc/server.go index 24602c1c..acb309df 100644 --- a/irc/server.go +++ b/irc/server.go @@ -81,7 +81,7 @@ type Server struct { rehashMutex sync.Mutex // tier 4 rehashSignal chan os.Signal pprofServer *http.Server - signals chan os.Signal + exitSignals chan os.Signal snomasks SnoManager store *buntdb.DB historyDB mysql.MySQL @@ -100,7 +100,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) { listeners: make(map[string]IRCListener), logger: logger, rehashSignal: make(chan os.Signal, 1), - signals: make(chan os.Signal, len(ServerExitSignals)), + exitSignals: make(chan os.Signal, len(ServerExitSignals)), defcon: 5, } @@ -115,7 +115,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) { } // Attempt to clean up when receiving these signals. - signal.Notify(server.signals, ServerExitSignals...) + signal.Notify(server.exitSignals, ServerExitSignals...) signal.Notify(server.rehashSignal, syscall.SIGHUP) time.AfterFunc(alwaysOnExpirationPollPeriod, server.handleAlwaysOnExpirations) @@ -126,6 +126,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) { // Shutdown shuts down the server. func (server *Server) Shutdown() { sdnotify.Stopping() + server.logger.Info("server", "Stopping server") //TODO(dan): Make sure we disallow new nicks for _, client := range server.clients.AllClients() { @@ -140,19 +141,17 @@ func (server *Server) Shutdown() { } server.historyDB.Close() + server.logger.Info("server", fmt.Sprintf("%s exiting", Ver)) } // Run starts the server. func (server *Server) Run() { - // defer closing db/store - defer server.store.Close() + defer server.Shutdown() for { select { - case <-server.signals: - server.Shutdown() + case <-server.exitSignals: return - case <-server.rehashSignal: server.logger.Info("server", "Rehashing due to SIGHUP") go server.rehash() @@ -714,14 +713,16 @@ func (server *Server) applyConfig(config *Config) (err error) { server.logger.Info("server", "Proxied IPs will be accepted from", strings.Join(config.Server.ProxyAllowedFrom, ", ")) } + // we are now ready to receive connections: err = server.setupListeners(config) - // send other config warnings - if config.Accounts.RequireSasl.Enabled && config.Accounts.Registration.Enabled { - server.logger.Warning("server", "Warning: although require-sasl is enabled, users can still register accounts. If your server is not intended to be public, you must set accounts.registration.enabled to false.") - } - // we are now open for business - sdnotify.Ready() + if err == nil { + // we are now open for business + if initial { + server.logger.Info("server", "Server running") + } + sdnotify.Ready() + } if !initial { // push new info to all of our clients @@ -736,6 +737,11 @@ func (server *Server) applyConfig(config *Config) (err error) { } } + // send other config warnings + if config.Accounts.RequireSasl.Enabled && config.Accounts.Registration.Enabled { + server.logger.Warning("server", "Warning: although require-sasl is enabled, users can still register accounts. If your server is not intended to be public, you must set accounts.registration.enabled to false.") + } + return err }