Feature: add reload signal support (#2908)

This commit is contained in:
septs 2023-08-28 21:44:08 +08:00 committed by GitHub
parent 0450860eea
commit 4a91932554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

19
main.go
View File

@ -94,7 +94,20 @@ func main() {
log.Fatalln("Parse config error: %s", err.Error()) log.Fatalln("Parse config error: %s", err.Error())
} }
sigCh := make(chan os.Signal, 1) termSign := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) hupSign := make(chan os.Signal, 1)
<-sigCh signal.Notify(termSign, syscall.SIGINT, syscall.SIGTERM)
signal.Notify(hupSign, syscall.SIGHUP)
for {
select {
case <-termSign:
return
case <-hupSign:
if cfg, err := executor.ParseWithPath(C.Path.Config()); err == nil {
executor.ApplyConfig(cfg, true)
} else {
log.Errorln("Parse config error: %s", err.Error())
}
}
}
} }