From c2b06a02bf8884b572955aed59303ec8e9cd821e Mon Sep 17 00:00:00 2001 From: Andrei Shevchuk Date: Fri, 29 Sep 2023 00:36:25 +0000 Subject: [PATCH] feat: add reload signal support (#780) Backport Clash feature by @septs, see Dreamacro/clash#2908 --- main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index e13b8dc8..e9f66058 100644 --- a/main.go +++ b/main.go @@ -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()) + } + } + } }