admin: /stop endpoint gracefully shuts down; fixes caddy stop command

This commit is contained in:
Matthew Holt 2019-12-16 13:46:13 -07:00
parent c3bcd967bd
commit 5ab17a3a37
2 changed files with 10 additions and 6 deletions

View file

@ -561,14 +561,20 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error {
} }
func handleStop(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) err := handleUnload(w, r)
if err != nil { if err != nil {
Log().Named("admin.api").Error("unload error", zap.Error(err)) 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 return nil
} }

View file

@ -239,8 +239,6 @@ func cmdStop(fl Flags) (int, error) {
if !found { if !found {
return caddy.ExitCodeFailedStartup, fmt.Errorf("Caddy is not running") return caddy.ExitCodeFailedStartup, fmt.Errorf("Caddy is not running")
} }
fmt.Println(" success")
} }
return caddy.ExitCodeSuccess, nil return caddy.ExitCodeSuccess, nil