1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

More shutdown work, closes #11

- Drain SMTP connections
- Force exit after 15 seconds of draining
This commit is contained in:
James Hillyerd
2012-11-16 21:29:53 -08:00
parent 7ccef7b977
commit 9ee9afe5cc
3 changed files with 35 additions and 10 deletions

View File

@@ -92,11 +92,14 @@ func main() {
fmt.Fprintf(pidf, "%v\n", os.Getpid())
}
// Startup SMTP server
smtpServer = smtpd.New()
go smtpServer.Start()
// Start HTTP server
go web.Start()
web.Start()
// Startup SMTP server, block until it exits
smtpServer = smtpd.New()
smtpServer.Start()
// Wait for active connections to finish
smtpServer.Drain()
}
// openLogFile creates or appends to the logfile passed on commandline
@@ -135,16 +138,24 @@ func signalProcessor(c <-chan os.Signal) {
case syscall.SIGTERM:
// Initiate shutdown
log.Info("Received SIGTERM, shutting down")
go timedExit()
web.Stop()
if smtpServer != nil {
smtpServer.Stop()
} else {
log.Error("smtpServer was nil during shutdown")
}
web.Stop()
}
}
}
// timedExit is called as a goroutine during shutdown, it will force an exit after 15 seconds
func timedExit() {
time.Sleep(15 * time.Second)
log.Error("Inbucket clean shutdown timed out, forcing exit")
os.Exit(0)
}
func init() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, "Usage of inbucket [options] <conf file>:")