mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 18:17:03 +00:00
Add SIGINT to traps, triggers clean shutdown
This commit is contained in:
28
inbucket.go
28
inbucket.go
@@ -66,7 +66,7 @@ func main() {
|
||||
|
||||
// Setup signal handler
|
||||
sigChan := make(chan os.Signal)
|
||||
signal.Notify(sigChan, syscall.SIGHUP, syscall.SIGTERM)
|
||||
signal.Notify(sigChan, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT)
|
||||
go signalProcessor(sigChan)
|
||||
|
||||
// Configure logging, close std* fds
|
||||
@@ -183,21 +183,31 @@ func signalProcessor(c <-chan os.Signal) {
|
||||
} else {
|
||||
log.Infof("Ignoring SIGHUP, logfile not configured")
|
||||
}
|
||||
case syscall.SIGINT:
|
||||
// Initiate shutdown
|
||||
log.Infof("Received SIGINT, shutting down")
|
||||
shutdown()
|
||||
case syscall.SIGTERM:
|
||||
// Initiate shutdown
|
||||
log.Infof("Received SIGTERM, shutting down")
|
||||
go timedExit()
|
||||
httpd.Stop()
|
||||
if smtpServer != nil {
|
||||
smtpServer.Stop()
|
||||
} else {
|
||||
log.Errorf("smtpServer was nil during shutdown")
|
||||
}
|
||||
shutdown()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// timedExit is called as a goroutine during shutdown, it will force an exit after 15 seconds
|
||||
// shutdown is called by signalProcessor() when we are asked to shut down
|
||||
func shutdown() {
|
||||
go timedExit()
|
||||
httpd.Stop()
|
||||
if smtpServer != nil {
|
||||
smtpServer.Stop()
|
||||
} else {
|
||||
log.Errorf("smtpServer was nil during shutdown")
|
||||
}
|
||||
}
|
||||
|
||||
// timedExit is called as a goroutine during shutdown, it will force an exit
|
||||
// after 15 seconds
|
||||
func timedExit() {
|
||||
time.Sleep(15 * time.Second)
|
||||
log.Errorf("Inbucket clean shutdown timed out, forcing exit")
|
||||
|
||||
Reference in New Issue
Block a user