mirror of
https://github.com/caddyserver/caddy.git
synced 2025-11-03 11:07:23 -05:00
50 lines
942 B
Go
50 lines
942 B
Go
// +build !windows
|
|
|
|
package caddy
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
func init() {
|
|
// Trap POSIX-only signals
|
|
go func() {
|
|
reload := make(chan os.Signal, 1)
|
|
signal.Notify(reload, syscall.SIGUSR1) // reload configuration
|
|
|
|
for {
|
|
<-reload
|
|
|
|
var updatedCaddyfile Input
|
|
|
|
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?)")
|
|
caddyfileMu.Unlock()
|
|
continue
|
|
}
|
|
if caddyfile.IsFile() {
|
|
body, err := ioutil.ReadFile(caddyfile.Path())
|
|
if err == nil {
|
|
caddyfile = CaddyfileInput{
|
|
Filepath: caddyfile.Path(),
|
|
Contents: body,
|
|
RealFile: true,
|
|
}
|
|
}
|
|
}
|
|
caddyfileMu.Unlock()
|
|
|
|
err := Restart(updatedCaddyfile)
|
|
if err != nil {
|
|
log.Printf("[ERROR] SIGUSR1: Restart returned: %v", err)
|
|
}
|
|
}
|
|
}()
|
|
}
|