mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-03 14:47:45 +01: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"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ func Restart(newCaddyfile Input) error {
|
||||||
caddyfileMu.Unlock()
|
caddyfileMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(os.Args) == 0 { // this should never happen...
|
if len(os.Args) == 0 { // this should never happen, but...
|
||||||
os.Args = []string{""}
|
os.Args = []string{""}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,12 +73,18 @@ func Restart(newCaddyfile Input) error {
|
||||||
}
|
}
|
||||||
serversMu.Unlock()
|
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
|
// Fork the process with the current environment and file descriptors
|
||||||
execSpec := &syscall.ProcAttr{
|
execSpec := &syscall.ProcAttr{
|
||||||
Env: os.Environ(),
|
Env: os.Environ(),
|
||||||
Files: fds,
|
Files: fds,
|
||||||
}
|
}
|
||||||
_, err = syscall.ForkExec(os.Args[0], os.Args, execSpec)
|
_, err = syscall.ForkExec(exepath, os.Args, execSpec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,14 @@ func init() {
|
||||||
caddyfileMu.Lock()
|
caddyfileMu.Lock()
|
||||||
if caddyfile == nil {
|
if caddyfile == nil {
|
||||||
// Hmm, did spawing process forget to close stdin? Anyhow, this is unusual.
|
// 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()
|
caddyfileMu.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if caddyfile.IsFile() {
|
if caddyfile.IsFile() {
|
||||||
body, err := ioutil.ReadFile(caddyfile.Path())
|
body, err := ioutil.ReadFile(caddyfile.Path())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
caddyfile = CaddyfileInput{
|
updatedCaddyfile = CaddyfileInput{
|
||||||
Filepath: caddyfile.Path(),
|
Filepath: caddyfile.Path(),
|
||||||
Contents: body,
|
Contents: body,
|
||||||
RealFile: true,
|
RealFile: true,
|
||||||
|
|
Loading…
Reference in a new issue