@marcel91200 / caddy Mirror · read-only / commits / cbb405f6
Fork 0

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

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.

Matthew Holt committed Dec 23, 2019 at 12:41 UTC cbb405f6aaee046c9de9ffb4f07ca824d9eedeb1
4 files changed +5 -36
cmd/commandfuncs.go
+2 -26
@@ -33,7 +33,6 @@ import (
33
34 "github.com/caddyserver/caddy/v2"
35 "github.com/caddyserver/caddy/v2/caddyconfig"
36 - "github.com/keybase/go-ps"
36 "github.com/mholt/certmagic"
37 "go.uber.org/zap"
38 )
@@ -211,34 +210,11 @@ func cmdStop(fl Flags) (int, error) {
210
211 err = apiRequest(req)
212 if err != nil {
214 - // if the caddy instance doesn't have an API listener set up,
215 - // or we are unable to reach it for some reason, try signaling it
216 -
217 - caddy.Log().Warn("unable to use API to stop instance; will try to signal the process",
213 + caddy.Log().Warn("failed using API to stop instance",
214 zap.String("endpoint", stopEndpoint),
215 zap.Error(err),
216 )
221 -
222 - processList, err := ps.Processes()
223 - if err != nil {
224 - return caddy.ExitCodeFailedStartup, fmt.Errorf("listing processes: %v", err)
225 - }
226 - thisProcName := getProcessName()
227 -
228 - var found bool
229 - for _, p := range processList {
230 - // the process we're looking for should have the same name as us but different PID
231 - if p.Executable() == thisProcName && p.Pid() != os.Getpid() {
232 - found = true
233 - fmt.Printf("pid=%d\n", p.Pid())
234 - if err := gracefullyStopProcess(p.Pid()); err != nil {
235 - return caddy.ExitCodeFailedStartup, err
236 - }
237 - }
238 - }
239 - if !found {
240 - return caddy.ExitCodeFailedStartup, fmt.Errorf("Caddy is not running")
241 - }
217 + return caddy.ExitCodeFailedStartup, err
218 }
219
220 return caddy.ExitCodeSuccess, nil
cmd/commands.go
+3 -7
@@ -134,13 +134,9 @@ not quit after printing, and can be useful for troubleshooting.`,
134 Long: `
135 Stops the background Caddy process as gracefully as possible.
136
137 -It will first try to use the admin API's /stop endpoint; the address of
138 -this request can be customized using the --address flag if it is not the
139 -default.
140 -
141 -If that fails for any reason, it will attempt to signal the first process
142 -it can find named the same as this one (os.Args[0]). On Windows, such
143 -a stop is forceful because Windows does not have signals.`,
137 +It requires that the admin API is enabled and accessible, since it will
138 +use the API's /stop endpoint. The address of this request can be
139 +customized using the --address flag if it is not the default.`,
140 Flags: func() *flag.FlagSet {
141 fs := flag.NewFlagSet("stop", flag.ExitOnError)
142 fs.String("address", "", "The address to use to reach the admin API endpoint, if not the default")
go.mod
-1
@@ -12,7 +12,6 @@ require (
12 github.com/ilibs/json5 v1.0.1
13 github.com/imdario/mergo v0.3.8 // indirect
14 github.com/jsternberg/zap-logfmt v1.2.0
15 - github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19
15 github.com/klauspost/compress v1.8.6
16 github.com/klauspost/cpuid v1.2.2
17 github.com/lucas-clemente/quic-go v0.14.1
go.sum
-2
@@ -143,8 +143,6 @@ github.com/jsternberg/zap-logfmt v1.2.0 h1:1v+PK4/B48cy8cfQbxL4FmmNZrjnIMr2BsnyE
143 github.com/jsternberg/zap-logfmt v1.2.0/go.mod h1:kz+1CUmCutPWABnNkOu9hOHKdT2q3TDYCcsFy9hpqb0=
144 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
145 github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
146 -github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 h1:WjT3fLi9n8YWh/Ih8Q1LHAPsTqGddPcHqscN+PJ3i68=
147 -github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ=
146 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
147 github.com/klauspost/compress v1.8.6 h1:970MQcQdxX7hfgc/aqmB4a3grW0ivUVV6i1TLkP8CiE=
148 github.com/klauspost/compress v1.8.6/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=