-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsignal.go
42 lines (37 loc) · 852 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
// Released under MIT License
// Copyright (c) 2022 domosekai
// Reacts on system signals
//go:build !windows
package main
import (
"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:
logger.Println("Received signal to reload files and clear cache")
if *ipFile != "" {
readIPRules(&ipRules, *ipFile)
}
if *hostFile != "" {
readHostRules(&hostRules, *hostFile)
}
slowIPSet.clear()
slowHostSet.clear()
blockedIPSet.clear()
blockedHostSet.clear()
logger.Println("Slow and blocked lists flushed")
case syscall.SIGUSR2:
if *logFile == "" {
break
}
logger.Println("Received signal to reopen log file")
logger.Open(*logFile, *logAppend)
}
}
}