diff options
author | Matthew Holt <[email protected]> | 2020-04-16 12:34:28 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2020-04-16 12:34:28 -0600 |
commit | 9a572635f581c57a6d09a107e506ffac2e970b03 (patch) | |
tree | 66a86a08f1cd3d4162e865489949b280be02fcb2 | |
parent | f5ccb904a3db2bffd980feee685afaa762224cb2 (diff) | |
download | caddy-9a572635f581c57a6d09a107e506ffac2e970b03.tar.gz caddy-9a572635f581c57a6d09a107e506ffac2e970b03.zip |
admin: Close admin endpoint when shutting down (fixes #3269)
-rw-r--r-- | sigtrap.go | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/sigtrap.go b/sigtrap.go index 88dbb6da6..08f03aa7f 100644 --- a/sigtrap.go +++ b/sigtrap.go @@ -53,20 +53,29 @@ func trapSignalsCrossPlatform() { } // gracefulStop exits the process as gracefully as possible. +// It always exits, even if there are errors shutting down. func gracefulStop(sigName string) { exitCode := ExitCodeSuccess + defer func() { + Log().Info("shutdown done", zap.String("signal", sigName)) + os.Exit(exitCode) + }() err := stopAndCleanup() if err != nil { - Log().Error("stopping", + Log().Error("stopping config", zap.String("signal", sigName), - zap.Error(err), - ) + zap.Error(err)) exitCode = ExitCodeFailedQuit } - Log().Info("shutdown done", zap.String("signal", sigName)) - os.Exit(exitCode) + err = stopAdminServer(adminServer) + if err != nil { + Log().Error("stopping admin endpoint", + zap.String("signal", sigName), + zap.Error(err)) + exitCode = ExitCodeFailedQuit + } } // Exit codes. Generally, you should NOT |