From 68e66964a55921059a8bae6aebd028cf26e6a682 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 7 May 2017 08:07:20 -0400 Subject: [PATCH] wire up signal handlers for sighup --- main.go | 2 ++ util/signals/unix.go | 38 ++++++++++++++++++++++++++++++++++++++ util/signals/win32.go | 7 +++++++ 3 files changed, 47 insertions(+) create mode 100644 util/signals/unix.go create mode 100644 util/signals/win32.go 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 +}