diff --git a/leapi.service b/leapi.service index da01788..6182477 100644 --- a/leapi.service +++ b/leapi.service @@ -6,9 +6,9 @@ After=network.target [Service] Type=simple -#ExecStartPre=/bin/sh -c 'until ping -c1 8.8.8.8 ; do sleep 1; done;' +#ExecStartPre= ExecStart=/opt/leapi/leapi -ExecReload=/bin/kill -HUP $MAINPID +ExecReload=/bin/kill -USR1 $MAINPID Restart=on-failure [Install] diff --git a/main.go b/main.go index 174d12e..13eed7d 100644 --- a/main.go +++ b/main.go @@ -305,15 +305,17 @@ func main() { syncScheme = "https://" syncPort = appconf.HTTPS_ServerPort + keyPath := appconf.TLSKeyPath + "00.key" + certPath := appconf.TLSChainPath + "00.crt" //certPair, err := tls.LoadX509KeyPair(appconf.TLSCertificateFile, appconf.TLSKeyPath) - if !fileExists(appconf.TLSChainPath) || !fileExists(appconf.TLSKeyPath) { + if !fileExists(certPath) || !fileExists(keyPath) { fmt.Println("Provided certificate and/or key file does not exist! Terminating.") log.Fatal("Provided certificate and/or key file does not exist! Terminating.") } //Create loader for cert files - kpr, err := NewKeypairReloader(appconf.TLSChainPath, appconf.TLSKeyPath) + kpr, err := NewKeypairReloader(certPath, keyPath) if err != nil { log.Fatal(err) } @@ -420,10 +422,10 @@ func NewKeypairReloader(certPath, keyPath string) (*keypairReloader, error) { result.cert = &cert go func() { c := make(chan os.Signal, 1) - signal.Notify(c, syscall.SIGHUP) + signal.Notify(c, syscall.SIGUSR1) for range c { - log.Printf("Received SIGHUP, reloading TLS certificate and key from %q and %q", appconf.TLSChainPath, appconf.TLSKeyPath) - fmt.Printf("Received SIGHUP, reloading TLS certificate and key from %q and %q\n", appconf.TLSChainPath, appconf.TLSKeyPath) + log.Printf("Received SIGHUP, reloading TLS certificate and key from %q and %q", certPath, keyPath) + fmt.Printf("Received SIGHUP, reloading TLS certificate and key from %q and %q\n", certPath, keyPath) if err := result.maybeReload(); err != nil { log.Printf("Keeping old TLS certificate because the new one could not be loaded: %v", err) fmt.Printf("Keeping old TLS certificate because the new one could not be loaded: %v", err)