1
0

Added SIGHUP handler to reopen logs. Removed closeSingal, and doneSignal moved to the bottom of main().

This commit is contained in:
Alexander Andreev 2022-05-25 00:37:33 +04:00
parent bf189d050a
commit 1c8beb69ce
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -93,17 +93,16 @@ func main() {
doneSignal := make(chan os.Signal, 1)
signal.Notify(doneSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
closeSignal := make(chan bool, 1)
logReopenSignal := make(chan os.Signal, 1)
signal.Notify(logReopenSignal, syscall.SIGHUP)
go func() {
for {
select {
case <-doneSignal:
if err := srv.Stop(); err != nil {
logErr.Fatalln("failed to properly shutdown a server:", err)
}
closeSignal <- true
case <-logReopenSignal:
logErr.Reopen(config.Log.Error)
logUpload.Reopen(config.Log.Upload)
logDownload.Reopen(config.Log.Download)
case <-uploadDirNotify:
sz, err := utils.DirectorySize(config.Uploads.Directory)
if err != nil {
@ -117,5 +116,9 @@ func main() {
}
}()
<-closeSignal
<-doneSignal
if err := srv.Stop(); err != nil {
logErr.Fatalln("failed to properly shutdown a server:", err)
}
}