From 4a919325544c355a8bda2125ff9309dadde7da3a Mon Sep 17 00:00:00 2001 From: septs Date: Mon, 28 Aug 2023 21:44:08 +0800 Subject: [PATCH] Feature: add reload signal support (#2908) --- main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index d94009d..55dd5eb 100644 --- a/main.go +++ b/main.go @@ -94,7 +94,20 @@ func main() { log.Fatalln("Parse config error: %s", err.Error()) } - 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()) + } + } + } }