From 3d8569d185ebb6990ae7c28104fb1b3f6d7a5376 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 8 Jan 2020 11:02:13 +0100 Subject: cmd/koushin: reload on SIGUSR1 References: https://todo.sr.ht/~sircmpwn/koushin/43 --- cmd/koushin/main.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'cmd') 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")) } -- cgit v1.2.3