Handle SIGHUP and reload config
This commit is contained in:
parent
8cdb62e56c
commit
2d4702781b
|
@ -4,7 +4,10 @@ import (
|
|||
"encoding/json"
|
||||
"flag"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"reflect"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -30,6 +33,19 @@ func Manage(target interface{}) {
|
|||
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
|
||||
// a field changes.
|
||||
func OnChange(field string, fun func(oldVal, newVal interface{})) {
|
||||
|
|
Loading…
Reference in New Issue