feat: add reload signal support (#780)
Backport Clash feature by @septs, see Dreamacro/clash#2908
This commit is contained in:
parent
e0458a8fde
commit
c2b06a02bf
1 changed files with 16 additions and 3 deletions
19
main.go
19
main.go
|
@ -115,7 +115,20 @@ func main() {
|
||||||
|
|
||||||
defer executor.Shutdown()
|
defer executor.Shutdown()
|
||||||
|
|
||||||
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue