diff options
author | Simon Ser <contact@emersion.fr> | 2020-01-08 11:02:13 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-01-08 11:02:39 +0100 |
commit | 3d8569d185ebb6990ae7c28104fb1b3f6d7a5376 (patch) | |
tree | 5501787636bf07f43c12096032e7d91737d7120c | |
parent | 97b314b6e7854612a2be31b2c46ad8907456551b (diff) | |
download | alps-3d8569d185ebb6990ae7c28104fb1b3f6d7a5376.tar.gz alps-3d8569d185ebb6990ae7c28104fb1b3f6d7a5376.zip |
cmd/koushin: reload on SIGUSR1
References: https://todo.sr.ht/~sircmpwn/koushin/43
-rw-r--r-- | cmd/koushin/main.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cmd/koushin/main.go b/cmd/koushin/main.go index 0f6c776..a0382dd 100644 --- a/cmd/koushin/main.go +++ b/cmd/koushin/main.go @@ -3,6 +3,9 @@ package main import ( "flag" "fmt" + "os" + "os/signal" + "syscall" "git.sr.ht/~emersion/koushin" "github.com/labstack/echo/v4" @@ -35,10 +38,22 @@ func main() { if l, ok := e.Logger.(*log.Logger); ok { l.SetHeader("${time_rfc3339} ${level}") } - _, err := koushin.New(e, &options) + s, err := koushin.New(e, &options) if err != nil { e.Logger.Fatal(err) } e.Use(middleware.Recover()) + + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGUSR1) + go func() { + for range sigs { + e.Logger.Printf("Reloading server") + if err := s.Reload(); err != nil { + e.Logger.Errorf("Failed to reload server: %v", err) + } + } + }() + e.Logger.Fatal(e.Start(":1323")) } |