Support reloading ACLs with SIGHUP

Also continously listen for signals, not just once.
This commit is contained in:
Kristoffer Dalby 2022-05-31 13:02:23 +02:00
parent 36dca3516a
commit 2feed18b28

13
app.go
View file

@ -728,6 +728,7 @@ func (h *Headscale) Serve() error {
syscall.SIGHUP) syscall.SIGHUP)
go func(c chan os.Signal) { go func(c chan os.Signal) {
// Wait for a SIGINT or SIGKILL: // Wait for a SIGINT or SIGKILL:
for {
sig := <-c sig := <-c
switch sig { switch sig {
case syscall.SIGHUP: case syscall.SIGHUP:
@ -737,6 +738,17 @@ func (h *Headscale) Serve() error {
// TODO(kradalby): Reload config on SIGHUP // TODO(kradalby): Reload config on SIGHUP
if h.cfg.ACL.PolicyPath != "" {
aclPath := AbsolutePathFromConfigPath(h.cfg.ACL.PolicyPath)
err := h.LoadACLPolicy(aclPath)
if err != nil {
log.Error().Err(err).Msg("Failed to reload ACL policy")
}
log.Info().
Str("path", aclPath).
Msg("ACL policy successfully reloaded")
}
default: default:
log.Info(). log.Info().
Str("signal", sig.String()). Str("signal", sig.String()).
@ -758,6 +770,7 @@ func (h *Headscale) Serve() error {
// And we're done: // And we're done:
os.Exit(0) os.Exit(0)
} }
}
}(sigc) }(sigc)
return errorGroup.Wait() return errorGroup.Wait()