From 6cdb2392d73992099955f9ce859748dea97cf4df Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 15 Nov 2019 15:45:18 -0700 Subject: cmd: Improve stop command by trying API before signaling process This allows graceful shutdown on all platforms --- cmd/commands.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'cmd/commands.go') diff --git a/cmd/commands.go b/cmd/commands.go index 7f43cd0..a861cdf 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -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{ -- cgit v1.2.3