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: /stop endpoint gracefully shuts down; fixes caddy stop command
Matthew Holt committed
Dec 16, 2019 at 13:46 UTC
5ab17a3a371c1f84ef5a649d9310971eb7959271
2 files changed
+10
-6
admin.go
+10
-4
@@ -561,14 +561,20 @@ func handleConfigID(w http.ResponseWriter, r *http.Request) error {
561
}
562
563
func handleStop(w http.ResponseWriter, r *http.Request) error {
564
- defer func() {
565
- Log().Named("admin.api").Info("stopping now, bye!! 👋")
566
- os.Exit(0)
567
- }()
564
err := handleUnload(w, r)
565
if err != nil {
566
Log().Named("admin.api").Error("unload error", zap.Error(err))
567
}
568
+ go func() {
569
+ err := stopAdminServer(adminServer)
570
+ var exitCode int
571
+ if err != nil {
572
+ exitCode = ExitCodeFailedQuit
573
+ Log().Named("admin.api").Error("failed to stop admin server gracefully", zap.Error(err))
574
+ }
575
+ Log().Named("admin.api").Info("stopping now, bye!! 👋")
576
+ os.Exit(exitCode)
577
+ }()
578
return nil
579
}
580
cmd/commandfuncs.go
-2
@@ -239,8 +239,6 @@ func cmdStop(fl Flags) (int, error) {
239
if !found {
240
return caddy.ExitCodeFailedStartup, fmt.Errorf("Caddy is not running")
241
}
242
-
243
- fmt.Println(" success")
242
}
243
244
return caddy.ExitCodeSuccess, nil