mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-13 22:51:08 -05:00
core: Fixed minor restart bug
Actually, restart on posix systems failed entirely if caddy was executed without the path included; also fixed a related bug where a variable was declared but never assigned.
This commit is contained in:
parent
4d78013646
commit
d46967d1e2
2 changed files with 11 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue