diff --git a/caddy/restart.go b/caddy/restart.go index 4b52cdac..d6acd0cf 100644 --- a/caddy/restart.go +++ b/caddy/restart.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "log" "os" + "os/exec" "syscall" ) @@ -33,7 +34,7 @@ func Restart(newCaddyfile Input) error { caddyfileMu.Unlock() } - if len(os.Args) == 0 { // this should never happen... + if len(os.Args) == 0 { // this should never happen, but... os.Args = []string{""} } @@ -72,12 +73,18 @@ func Restart(newCaddyfile Input) error { } serversMu.Unlock() + // We're gonna need the proper path to the executable + exepath, err := exec.LookPath(os.Args[0]) + if err != nil { + return err + } + // Fork the process with the current environment and file descriptors execSpec := &syscall.ProcAttr{ Env: os.Environ(), Files: fds, } - _, err = syscall.ForkExec(os.Args[0], os.Args, execSpec) + _, err = syscall.ForkExec(exepath, os.Args, execSpec) if err != nil { return err } diff --git a/caddy/sigtrap_posix.go b/caddy/sigtrap_posix.go index 8f7aaade..e2f326b7 100644 --- a/caddy/sigtrap_posix.go +++ b/caddy/sigtrap_posix.go @@ -24,14 +24,14 @@ func init() { caddyfileMu.Lock() if caddyfile == nil { // Hmm, did spawing process forget to close stdin? Anyhow, this is unusual. - log.Println("[ERROR] SIGUSR1: no caddyfile to reload (was stdin left open?)") + log.Println("[ERROR] SIGUSR1: no Caddyfile to reload (was stdin left open?)") caddyfileMu.Unlock() continue } if caddyfile.IsFile() { body, err := ioutil.ReadFile(caddyfile.Path()) if err == nil { - caddyfile = CaddyfileInput{ + updatedCaddyfile = CaddyfileInput{ Filepath: caddyfile.Path(), Contents: body, RealFile: true,