settings: reload through SIGHUP
authorPierre-Olivier Mercier <nemunaire@nemunai.re>
Sun, 9 Dec 2018 18:55:54 +0000 (19:55 +0100)
committerPierre-Olivier Mercier <nemunaire@nemunai.re>
Sun, 9 Dec 2018 23:31:29 +0000 (00:31 +0100)
settings/settings.go

index 700bb9c..63f7a89 100644 (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)