From bb14fabc99640c81f1740fd2b726582af8f467b7 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 29 Aug 2019 18:21:14 +0300 Subject: [PATCH] Added reload as signal response --- cmd/cgr-engine/cgr-engine.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index c79252914..9d5983543 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -1509,11 +1509,31 @@ func cpuProfiling(cpuProfDir string, stopChan, doneChan chan struct{}, exitChan doneChan <- struct{}{} } -func shutdownSingnalHandler(exitChan chan bool) { - c := make(chan os.Signal) - signal.Notify(c, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT) - <-c - exitChan <- true +func singnalHandler(exitChan chan bool) { + shutdownSignal := make(chan os.Signal) + reloadSignal := make(chan os.Signal) + signal.Notify(shutdownSignal, os.Interrupt, + syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT) + signal.Notify(reloadSignal, syscall.SIGHUP) + for { + select { + case <-shutdownSignal: + exitChan <- true + case <-reloadSignal: + // do it in it's own gorutine in order to not block the signal handler with the reload functionality + go func() { + var reply string + if err := config.CgrConfig().V1ReloadConfig( + &config.ConfigReloadWithArgDispatcher{ + Section: utils.EmptyString, + Path: config.CgrConfig().ConfigPath, // use the same path + }, &reply); err != nil { + utils.Logger.Warning( + fmt.Sprintf("Error reloading configuration: <%s>", err)) + } + }() + } + } } func main() { @@ -1533,7 +1553,7 @@ func main() { } exitChan := make(chan bool) - go shutdownSingnalHandler(exitChan) + go singnalHandler(exitChan) if *memProfDir != "" { go memProfiling(*memProfDir, *memProfInterval, *memProfNrFiles, exitChan)