Add SIGHUP handler to reload config file
This commit is contained in:
20
tendrils.go
20
tendrils.go
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user