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)
go func(c chan os.Signal) {
// Wait for a SIGINT or SIGKILL:
for {
sig := <-c
switch sig {
case syscall.SIGHUP:
@ -737,6 +738,17 @@ func (h *Headscale) Serve() error {
// 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:
log.Info().
Str("signal", sig.String()).
@ -758,6 +770,7 @@ func (h *Headscale) Serve() error {
// And we're done:
os.Exit(0)
}
}
}(sigc)
return errorGroup.Wait()