-
Notifications
You must be signed in to change notification settings - Fork 5
/
signal.go
46 lines (39 loc) · 943 Bytes
/
signal.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
42
43
44
45
46
// Reacts on system signals
//go:build !windows
package main
import (
"log"
"os"
"os/signal"
"syscall"
)
func listenSignal() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGHUP, syscall.SIGUSR2)
for sig := range sigs {
switch sig {
case syscall.SIGHUP:
lg.Println("Received signal to reload files")
// Read DNS suffix from file
if n := suffixes.read(*suffixFile); n > 0 {
lg.Printf("Loaded %d suffixes", n)
} else {
log.Fatalf("At least 1 DNS suffix is needed")
}
// Read server credentials
if n := auths.read(*authFile); n > 0 {
lg.Printf("Loaded %d server credentials", n)
} else {
log.Fatalf("At least 1 server credential is needed")
}
// Remove outdated server control sessions
sessions.cleanupServers()
case syscall.SIGUSR2:
if *logFile == "" {
break
}
lg.Println("Received signal to reopen log file")
lg.Open(*logFile, false)
}
}
}