reload templates on USR1

This commit is contained in:
stryan 2021-04-08 13:22:48 -04:00
parent b448a91d55
commit c147c217de
2 changed files with 18 additions and 0 deletions

View File

@ -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

15
main.go
View File

@ -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 == "" {