diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-12-23 12:41:05 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-12-23 12:41:05 -0700 |
commit | cbb405f6aaee046c9de9ffb4f07ca824d9eedeb1 (patch) | |
tree | 5e1ed490037901854c30053cfee772cb858b9a90 /cmd | |
parent | 724c72867835f9287b3df3ee5a0d75327c0780cf (diff) |
cmd: Eliminate unintended use of cgo
This means the stop command can only use the API to stop the instance;
no more signaling, unless we find a cgo-free way of doing it.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/commandfuncs.go | 28 | ||||
-rw-r--r-- | cmd/commands.go | 10 |
2 files changed, 5 insertions, 33 deletions
diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go index 5079449..6dc7c52 100644 --- a/cmd/commandfuncs.go +++ b/cmd/commandfuncs.go @@ -33,7 +33,6 @@ import ( "github.com/caddyserver/caddy/v2" "github.com/caddyserver/caddy/v2/caddyconfig" - "github.com/keybase/go-ps" "github.com/mholt/certmagic" "go.uber.org/zap" ) @@ -211,34 +210,11 @@ func cmdStop(fl Flags) (int, error) { err = apiRequest(req) if err != nil { - // if the caddy instance doesn't have an API listener set up, - // or we are unable to reach it for some reason, try signaling it - - caddy.Log().Warn("unable to use API to stop instance; will try to signal the process", + caddy.Log().Warn("failed using API to stop instance", zap.String("endpoint", stopEndpoint), zap.Error(err), ) - - processList, err := ps.Processes() - if err != nil { - return caddy.ExitCodeFailedStartup, fmt.Errorf("listing processes: %v", err) - } - thisProcName := getProcessName() - - var found bool - for _, p := range processList { - // the process we're looking for should have the same name as us but different PID - if p.Executable() == thisProcName && p.Pid() != os.Getpid() { - found = true - fmt.Printf("pid=%d\n", p.Pid()) - if err := gracefullyStopProcess(p.Pid()); err != nil { - return caddy.ExitCodeFailedStartup, err - } - } - } - if !found { - return caddy.ExitCodeFailedStartup, fmt.Errorf("Caddy is not running") - } + return caddy.ExitCodeFailedStartup, err } return caddy.ExitCodeSuccess, nil diff --git a/cmd/commands.go b/cmd/commands.go index a861cdf..971d8d9 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -134,13 +134,9 @@ not quit after printing, and can be useful for troubleshooting.`, Long: ` Stops the background Caddy process as gracefully as possible. -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. - -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.`, +It requires that the admin API is enabled and accessible, since it will +use the API's /stop endpoint. The address of this request can be +customized using the --address flag if it is not the default.`, 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") |