Reopen log files after receiving a SIGHUP signal (#13112)
* Reopen log files after receiving a SIGHUP signal Implements a system signals listener in log.FileLogWriter. After receiving a SIGHUP signal from the system, the listener will close the current log file and then open it again. The listener will finishes after receiving a SIGINT, SIGKILL or SIGTERM signal. Closes grafana/grafana#2497 * Move the SIGHUP handling to the main file
This commit is contained in:
@@ -96,13 +96,17 @@ func main() {
|
||||
|
||||
func listenToSystemSignals(server *GrafanaServerImpl) {
|
||||
signalChan := make(chan os.Signal, 1)
|
||||
ignoreChan := make(chan os.Signal, 1)
|
||||
sighupChan := make(chan os.Signal, 1)
|
||||
|
||||
signal.Notify(ignoreChan, syscall.SIGHUP)
|
||||
signal.Notify(sighupChan, syscall.SIGHUP)
|
||||
signal.Notify(signalChan, os.Interrupt, os.Kill, syscall.SIGTERM)
|
||||
|
||||
select {
|
||||
case sig := <-signalChan:
|
||||
server.Shutdown(fmt.Sprintf("System signal: %s", sig))
|
||||
for {
|
||||
select {
|
||||
case _ = <-sighupChan:
|
||||
log.Reload()
|
||||
case sig := <-signalChan:
|
||||
server.Shutdown(fmt.Sprintf("System signal: %s", sig))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user