settings: reload through SIGHUP

This commit is contained in:
nemunaire 2018-12-09 19:55:54 +01:00
parent ab67146c0f
commit 3a372b85c5
1 changed files with 16 additions and 0 deletions

View File

@ -6,8 +6,10 @@ import (
"encoding/json"
"log"
"os"
"os/signal"
"path"
"time"
"syscall"
"gopkg.in/fsnotify.v1"
)
@ -117,6 +119,20 @@ func LoadAndWatchSettings(settingsPath string, reload func (FICSettings)) {
}
}
// Register SIGHUP
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
go func(){
for range c {
log.Println("SIGHUP received, reloading settings...")
if config, err := ReadSettings(settingsPath); err != nil {
log.Println("ERROR: Unable to read challenge settings:", err)
} else {
reload(config)
}
}
}()
// Watch the configuration file
if watcher, err := fsnotify.NewWatcher(); err != nil {
log.Fatal(err)