diff --git a/main.go b/main.go index 6b191fb3..7c18a42c 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "github.com/ewhal/nyaa/db" "github.com/ewhal/nyaa/router" "github.com/ewhal/nyaa/util/log" + "github.com/ewhal/nyaa/util/signals" "net/http" "os" @@ -54,6 +55,7 @@ func main() { } db.ORM, _ = db.GormInit(conf) initI18N() + go signals.Handle() RunServer(conf) } } diff --git a/util/signals/unix.go b/util/signals/unix.go new file mode 100644 index 00000000..091bb25e --- /dev/null +++ b/util/signals/unix.go @@ -0,0 +1,38 @@ +// +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) + for { + sig, ok := <-chnl + if !ok { + break + } + switch sig { + case syscall.SIGHUP: + handleReload() + break + default: + break + } + } +} diff --git a/util/signals/win32.go b/util/signals/win32.go new file mode 100644 index 00000000..9554cce2 --- /dev/null +++ b/util/signals/win32.go @@ -0,0 +1,7 @@ +// +build win32 + +package signals + +func Handle() { + // windows has no sighup LOOOOL, this does nothing +}