Handle SIGHUP and reload config
This commit is contained in:
parent
8cdb62e56c
commit
2d4702781b
|
@ -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{})) {
|
||||||
|
|
Loading…
Reference in New Issue