Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
admin: Close admin endpoint when shutting down (fixes #3269)
Matthew Holt committed
Apr 16, 2020 at 12:34 UTC
9a572635f581c57a6d09a107e506ffac2e970b03
1 file changed
+14
-5
sigtrap.go
+14
-5
@@ -53,20 +53,29 @@ func trapSignalsCrossPlatform() {
53
}
54
55
// gracefulStop exits the process as gracefully as possible.
56
+// It always exits, even if there are errors shutting down.
57
func gracefulStop(sigName string) {
58
exitCode := ExitCodeSuccess
59
+ defer func() {
60
+ Log().Info("shutdown done", zap.String("signal", sigName))
61
+ os.Exit(exitCode)
62
+ }()
63
64
err := stopAndCleanup()
65
if err != nil {
61
- Log().Error("stopping",
66
+ Log().Error("stopping config",
67
zap.String("signal", sigName),
63
- zap.Error(err),
64
- )
68
+ zap.Error(err))
69
exitCode = ExitCodeFailedQuit
70
}
71
68
- Log().Info("shutdown done", zap.String("signal", sigName))
69
- os.Exit(exitCode)
72
+ err = stopAdminServer(adminServer)
73
+ if err != nil {
74
+ Log().Error("stopping admin endpoint",
75
+ zap.String("signal", sigName),
76
+ zap.Error(err))
77
+ exitCode = ExitCodeFailedQuit
78
+ }
79
}
80
81
// Exit codes. Generally, you should NOT