From c147c217ded82610b26dceaef89abb984faba519 Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 8 Apr 2021 13:22:48 -0400 Subject: [PATCH] reload templates on USR1 --- init/guildgate.service | 3 +++ main.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/init/guildgate.service b/init/guildgate.service index 1fedc4c..04757cd 100644 --- a/init/guildgate.service +++ b/init/guildgate.service @@ -2,12 +2,15 @@ Description=Guildgate: A web front-end for LDAP After=network.target StartLimitIntervalSec=0 + [Service] Type=simple Restart=always RestartSec=1 User=root ExecStart=/usr/local/bin/guildgate +ExecReload=/bin/kill -HUP $MAINPID + [Install] WantedBy=multi-user.target diff --git a/main.go b/main.go index 0cf0f1f..6c877ed 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,9 @@ package main import ( "log" "net/http" + "os" + "os/signal" + "syscall" "text/template" "github.com/gorilla/mux" @@ -59,6 +62,18 @@ func main() { } passwordTokenSet = make(map[string]bool) log.Printf("Guildgate v%v starting on %v\n", version, Conf.Port) + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGUSR1) + go func() { + for { + <-sigs + log.Println("reloading templates on SIGUSR1") + tpl = template.Must(template.ParseGlob(Conf.TplPath + "/*")) + if Conf.UserTplPath != "" { + tpl = template.Must(tpl.ParseGlob(Conf.UserTplPath + "/*")) + } + } + }() if Conf.Tls { log.Printf("Starting TLS\n") if Conf.Cert == "" {