Added SIGHUP handler to reopen logs. Removed closeSingal, and doneSignal moved to the bottom of main().
This commit is contained in:
parent
bf189d050a
commit
1c8beb69ce
@ -93,17 +93,16 @@ func main() {
|
|||||||
|
|
||||||
doneSignal := make(chan os.Signal, 1)
|
doneSignal := make(chan os.Signal, 1)
|
||||||
signal.Notify(doneSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
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() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-doneSignal:
|
case <-logReopenSignal:
|
||||||
if err := srv.Stop(); err != nil {
|
logErr.Reopen(config.Log.Error)
|
||||||
logErr.Fatalln("failed to properly shutdown a server:", err)
|
logUpload.Reopen(config.Log.Upload)
|
||||||
}
|
logDownload.Reopen(config.Log.Download)
|
||||||
|
|
||||||
closeSignal <- true
|
|
||||||
case <-uploadDirNotify:
|
case <-uploadDirNotify:
|
||||||
sz, err := utils.DirectorySize(config.Uploads.Directory)
|
sz, err := utils.DirectorySize(config.Uploads.Directory)
|
||||||
if err != nil {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user