73f77f1624
This makes systemd not put unit into fail mode when stopping INFO: * make sure to use signals.RegisterCloser for everything that should be closed on interrupt * for any net.Listeners created make sure to wrap them with network.WrapListener and register with signals.RegisterCloser
47 lignes
721 o
Go
47 lignes
721 o
Go
// +build !win32
|
|
|
|
package signals
|
|
|
|
import (
|
|
"github.com/ewhal/nyaa/router"
|
|
"github.com/ewhal/nyaa/util/log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
)
|
|
|
|
func handleReload() {
|
|
log.Info("Got SIGHUP")
|
|
router.ReloadTemplates()
|
|
log.Info("reloaded templates")
|
|
|
|
}
|
|
|
|
// Handle signals
|
|
// returns when done
|
|
func Handle() {
|
|
chnl := make(chan os.Signal)
|
|
signal.Notify(chnl, syscall.SIGHUP, os.Interrupt)
|
|
for {
|
|
sig, ok := <-chnl
|
|
if !ok {
|
|
break
|
|
}
|
|
switch sig {
|
|
case syscall.SIGHUP:
|
|
handleReload()
|
|
break
|
|
case os.Interrupt:
|
|
interrupted()
|
|
return
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
// unix implementation of interrupt
|
|
// called in interrupted()
|
|
func handleInterrupt() {
|
|
// XXX: put unix specific cleanup here as needed
|
|
}
|