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

Remove PID file during shutdown

This commit is contained in:
James Hillyerd
2016-02-28 14:41:15 -08:00
parent 3f654e48be
commit 075aa0dd38
2 changed files with 9 additions and 4 deletions

View File

@@ -41,7 +41,6 @@ func Initialize(cfg config.WebConfig, ds smtpd.DataStore) {
// NewContext() will use this DataStore for the web handlers
DataStore = ds
// TODO Make configurable
if cfg.CookieAuthKey == "" {
log.Infof("HTTP generating random cookie.auth.key")
sessionStore = sessions.NewCookieStore(securecookie.GenerateRandomKey(64))

View File

@@ -107,16 +107,15 @@ func main() {
log.Infof("Inbucket %v (%v) starting...", config.Version, config.BuildDate)
// Write pidfile if requested
// TODO: Probably supposed to remove pidfile during shutdown
if *pidfile != "none" {
pidf, err := os.Create(*pidfile)
if err != nil {
log.Errorf("Failed to create %v: %v", *pidfile, err)
log.Errorf("Failed to create %q: %v", *pidfile, err)
os.Exit(1)
}
fmt.Fprintf(pidf, "%v\n", os.Getpid())
if err := pidf.Close(); err != nil {
log.Errorf("Failed to close PID file %v: %v", *pidfile, err)
log.Errorf("Failed to close PID file %q: %v", *pidfile, err)
}
}
@@ -140,6 +139,13 @@ func main() {
// Wait for active connections to finish
smtpServer.Drain()
pop3Server.Drain()
// Remove pidfile
if *pidfile != "none" {
if err := os.Remove(*pidfile); err != nil {
log.Errorf("Failed to remove %q: %v", *pidfile, err)
}
}
}
// openLogFile creates or appends to the logfile passed on commandline