1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 01:57:02 +00:00

Basic SIGTERM handling

This commit is contained in:
James Hillyerd
2012-11-16 20:44:41 -08:00
parent cabc5f0d2b
commit 7ccef7b977
3 changed files with 76 additions and 13 deletions

View File

@@ -29,6 +29,8 @@ var startTime = time.Now()
// The file we send log output to, will be nil for stderr or stdout
var logf *os.File
var smtpServer *smtpd.Server
func main() {
flag.Parse()
if *help {
@@ -49,7 +51,7 @@ func main() {
// Setup signal handler
sigChan := make(chan os.Signal)
signal.Notify(sigChan, syscall.SIGHUP)
signal.Notify(sigChan, syscall.SIGHUP, syscall.SIGTERM)
go signalProcessor(sigChan)
// Configure logging, close std* fds
@@ -91,8 +93,8 @@ func main() {
}
// Startup SMTP server
server := smtpd.New()
go server.Start()
smtpServer = smtpd.New()
go smtpServer.Start()
web.Start()
}
@@ -130,6 +132,15 @@ func signalProcessor(c <-chan os.Signal) {
} else {
log.Info("Ignoring SIGHUP, logfile not configured")
}
case syscall.SIGTERM:
// Initiate shutdown
log.Info("Received SIGTERM, shutting down")
if smtpServer != nil {
smtpServer.Stop()
} else {
log.Error("smtpServer was nil during shutdown")
}
web.Stop()
}
}
}