cmd: Improve stop command by trying API before signaling process

This allows graceful shutdown on all platforms
This commit is contained in:
Matthew Holt
2019-11-15 15:45:18 -07:00
parent 0ca109db4a
commit 6cdb2392d7
4 changed files with 87 additions and 39 deletions

View File

@ -134,11 +134,18 @@ not quit after printing, and can be useful for troubleshooting.`,
Long: `
Stops the background Caddy process as gracefully as possible.
On Windows, this stop is forceful and Caddy will not have an opportunity to
clean up any active locks; for a graceful shutdown on Windows, use Ctrl+C
or the /stop API endpoint.
It will first try to use the admin API's /stop endpoint; the address of
this request can be customized using the --address flag if it is not the
default.
Note: this will stop any process named the same as the executable (os.Args[0]).`,
If that fails for any reason, it will attempt to signal the first process
it can find named the same as this one (os.Args[0]). On Windows, such
a stop is forceful because Windows does not have signals.`,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("stop", flag.ExitOnError)
fs.String("address", "", "The address to use to reach the admin API endpoint, if not the default")
return fs
}(),
})
RegisterCommand(Command{