From 5ab17a3a371c1f84ef5a649d9310971eb7959271 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 16 Dec 2019 13:46:13 -0700 Subject: [PATCH] admin: /stop endpoint gracefully shuts down; fixes caddy stop command --- admin.go | 14 ++++++++++---- cmd/commandfuncs.go | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/admin.go b/admin.go index d6f1787a..0f8144b2 100644 --- a/admin.go +++ b/admin.go @@ -561,14 +561,20 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error { } func handleStop(w http.ResponseWriter, r *http.Request) error { - defer func() { - Log().Named("admin.api").Info("stopping now, bye!! 👋") - os.Exit(0) - }() err := handleUnload(w, r) if err != nil { Log().Named("admin.api").Error("unload error", zap.Error(err)) } + go func() { + err := stopAdminServer(adminServer) + var exitCode int + if err != nil { + exitCode = ExitCodeFailedQuit + Log().Named("admin.api").Error("failed to stop admin server gracefully", zap.Error(err)) + } + Log().Named("admin.api").Info("stopping now, bye!! 👋") + os.Exit(exitCode) + }() return nil } diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go index 3cba47af..5079449d 100644 --- a/cmd/commandfuncs.go +++ b/cmd/commandfuncs.go @@ -239,8 +239,6 @@ func cmdStop(fl Flags) (int, error) { if !found { return caddy.ExitCodeFailedStartup, fmt.Errorf("Caddy is not running") } - - fmt.Println(" success") } return caddy.ExitCodeSuccess, nil