1
0
Fork 0

Handle SIGHUP and reload config

This commit is contained in:
Gregory Eremin 2015-08-29 14:14:53 +03:00
parent 8cdb62e56c
commit 2d4702781b
1 changed files with 16 additions and 0 deletions

View File

@ -4,7 +4,10 @@ import (
"encoding/json" "encoding/json"
"flag" "flag"
"log" "log"
"os"
"os/signal"
"reflect" "reflect"
"syscall"
) )
var ( var (
@ -30,6 +33,19 @@ func Manage(target interface{}) {
bootstrap() bootstrap()
} }
// HandleSIGHUP waits a SIGHUP system call and reloads configuration when
// receives one.
func HandleSIGHUP() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGHUP)
go func() {
for _ = range ch {
log.Println("SIGHUP received, reloading config")
readConfig()
}
}()
}
// OnChange adds a callback function that is triggered every time a value of // OnChange adds a callback function that is triggered every time a value of
// a field changes. // a field changes.
func OnChange(field string, fun func(oldVal, newVal interface{})) { func OnChange(field string, fun func(oldVal, newVal interface{})) {