3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00

refactor some start-stop logging

This commit is contained in:
Shivaram Lingamneni 2021-07-04 17:58:48 -04:00
parent 6f24082705
commit 364193df4e
2 changed files with 20 additions and 18 deletions

View File

@ -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()
}

View File

@ -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
}