-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.go
41 lines (36 loc) · 807 Bytes
/
hook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package tls
import (
"github.com/coredns/caddy"
)
type renewCert struct {
quit chan bool
renew chan bool
}
// restarting CoreDNS is necessary when a cert is to be renewed
func hook(event caddy.EventName, info interface{}) error {
if event != caddy.InstanceStartupEvent {
return nil
}
// this should be an instance. ok to panic if not
instance := info.(*caddy.Instance)
go func() {
for {
select {
case <-r.renew:
corefile, err := caddy.LoadCaddyfile(instance.Caddyfile().ServerType())
if err != nil {
continue
}
_, err = instance.Restart(corefile)
if err != nil {
log.Errorf("Error during Restart: %v, \n", err)
}
return
case <-r.quit:
log.Debug("Received quit signal, stopping certificate renewal")
return
}
}
}()
return nil
}