Browse Source

Fixed certificate locations for multi-domain, and changed SIGHUP to SIGUSR1 for reloading certs.

multicert
Ruel Tmeizeh - RuhNet 2 years ago
parent
commit
1a3f01939d
2 changed files with 9 additions and 7 deletions
  1. +2
    -2
      leapi.service
  2. +7
    -5
      main.go

+ 2
- 2
leapi.service View File

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


+ 7
- 5
main.go View File

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


Loading…
Cancel
Save