mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added reload as signal response
This commit is contained in:
committed by
Dan Christian Bogos
parent
ed91536587
commit
bb14fabc99
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user