Add SIGHUP handler to reload config file

This commit is contained in:
Ian Gulliver
2026-01-25 09:38:52 -08:00
parent 142143f8d4
commit 3a33ece7d9

View File

@@ -77,14 +77,28 @@ func (t *Tendrils) Run() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
sigCh := make(chan os.Signal, 1) sigUsr1Ch := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGUSR1) signal.Notify(sigUsr1Ch, syscall.SIGUSR1)
go func() { go func() {
for range sigCh { for range sigUsr1Ch {
t.nodes.LogAll() t.nodes.LogAll()
} }
}() }()
sigHupCh := make(chan os.Signal, 1)
signal.Notify(sigHupCh, syscall.SIGHUP)
go func() {
for range sigHupCh {
cfg, err := LoadConfig(t.ConfigFile)
if err != nil {
log.Printf("[ERROR] failed to reload config: %v", err)
continue
}
t.config = cfg
log.Printf("reloaded config from %s", t.ConfigFile)
}
}()
cfg, err := LoadConfig(t.ConfigFile) cfg, err := LoadConfig(t.ConfigFile)
if err != nil { if err != nil {
log.Printf("[ERROR] failed to load config: %v", err) log.Printf("[ERROR] failed to load config: %v", err)