feat: add reload signal support (#780)

Backport Clash feature by @septs, see Dreamacro/clash#2908
This commit is contained in:
Andrei Shevchuk 2023-09-29 00:36:25 +00:00 committed by GitHub
parent e0458a8fde
commit c2b06a02bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

19
main.go
View file

@ -115,7 +115,20 @@ func main() {
defer executor.Shutdown()
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
<-sigCh
termSign := make(chan os.Signal, 1)
hupSign := make(chan os.Signal, 1)
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())
}
}
}
}