mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 05:19:25 +01:00
refactor some start-stop logging
This commit is contained in:
parent
6f24082705
commit
364193df4e
4
ergo.go
4
ergo.go
@ -192,10 +192,6 @@ Options:
|
|||||||
logman.Error("server", fmt.Sprintf("Could not load server: %s", err.Error()))
|
logman.Error("server", fmt.Sprintf("Could not load server: %s", err.Error()))
|
||||||
os.Exit(1)
|
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) {
|
if !arguments["--smoke"].(bool) {
|
||||||
server.Run()
|
server.Run()
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ type Server struct {
|
|||||||
rehashMutex sync.Mutex // tier 4
|
rehashMutex sync.Mutex // tier 4
|
||||||
rehashSignal chan os.Signal
|
rehashSignal chan os.Signal
|
||||||
pprofServer *http.Server
|
pprofServer *http.Server
|
||||||
signals chan os.Signal
|
exitSignals chan os.Signal
|
||||||
snomasks SnoManager
|
snomasks SnoManager
|
||||||
store *buntdb.DB
|
store *buntdb.DB
|
||||||
historyDB mysql.MySQL
|
historyDB mysql.MySQL
|
||||||
@ -100,7 +100,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
|||||||
listeners: make(map[string]IRCListener),
|
listeners: make(map[string]IRCListener),
|
||||||
logger: logger,
|
logger: logger,
|
||||||
rehashSignal: make(chan os.Signal, 1),
|
rehashSignal: make(chan os.Signal, 1),
|
||||||
signals: make(chan os.Signal, len(ServerExitSignals)),
|
exitSignals: make(chan os.Signal, len(ServerExitSignals)),
|
||||||
defcon: 5,
|
defcon: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to clean up when receiving these signals.
|
// Attempt to clean up when receiving these signals.
|
||||||
signal.Notify(server.signals, ServerExitSignals...)
|
signal.Notify(server.exitSignals, ServerExitSignals...)
|
||||||
signal.Notify(server.rehashSignal, syscall.SIGHUP)
|
signal.Notify(server.rehashSignal, syscall.SIGHUP)
|
||||||
|
|
||||||
time.AfterFunc(alwaysOnExpirationPollPeriod, server.handleAlwaysOnExpirations)
|
time.AfterFunc(alwaysOnExpirationPollPeriod, server.handleAlwaysOnExpirations)
|
||||||
@ -126,6 +126,7 @@ func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
|
|||||||
// Shutdown shuts down the server.
|
// Shutdown shuts down the server.
|
||||||
func (server *Server) Shutdown() {
|
func (server *Server) Shutdown() {
|
||||||
sdnotify.Stopping()
|
sdnotify.Stopping()
|
||||||
|
server.logger.Info("server", "Stopping server")
|
||||||
|
|
||||||
//TODO(dan): Make sure we disallow new nicks
|
//TODO(dan): Make sure we disallow new nicks
|
||||||
for _, client := range server.clients.AllClients() {
|
for _, client := range server.clients.AllClients() {
|
||||||
@ -140,19 +141,17 @@ func (server *Server) Shutdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server.historyDB.Close()
|
server.historyDB.Close()
|
||||||
|
server.logger.Info("server", fmt.Sprintf("%s exiting", Ver))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the server.
|
// Run starts the server.
|
||||||
func (server *Server) Run() {
|
func (server *Server) Run() {
|
||||||
// defer closing db/store
|
defer server.Shutdown()
|
||||||
defer server.store.Close()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-server.signals:
|
case <-server.exitSignals:
|
||||||
server.Shutdown()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-server.rehashSignal:
|
case <-server.rehashSignal:
|
||||||
server.logger.Info("server", "Rehashing due to SIGHUP")
|
server.logger.Info("server", "Rehashing due to SIGHUP")
|
||||||
go server.rehash()
|
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, ", "))
|
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)
|
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.")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
// we are now open for business
|
// we are now open for business
|
||||||
|
if initial {
|
||||||
|
server.logger.Info("server", "Server running")
|
||||||
|
}
|
||||||
sdnotify.Ready()
|
sdnotify.Ready()
|
||||||
|
}
|
||||||
|
|
||||||
if !initial {
|
if !initial {
|
||||||
// push new info to all of our clients
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user