-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (53 loc) · 1.15 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"github.com/evsio0n/log"
"netflix_agent/utils"
"os"
"os/signal"
"syscall"
"time"
)
var err error
func init() {
log.SetDebug(utils.IsDebug)
log.IsShowLogCatagory(false)
log.SetSyslog(utils.IsSyslog, "netflix-agent")
log.IsShowDate(utils.LogHaseDate)
err = utils.ChangeIPv6()
if err != nil {
log.Fatal(err.Error())
os.Exit(1)
}
}
func main() {
signalChannel := make(chan os.Signal, 2)
signal.Notify(signalChannel, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGUSR1, os.Interrupt)
go func() {
sig := <-signalChannel
for {
switch sig {
case syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, os.Interrupt:
log.Info("get a signal:" + sig.String() + " , stop the process")
utils.FlushNAT()
log.Info("flush nat iptables success, exiting...")
os.Exit(0)
}
}
}()
detectBlock()
}
func detectBlock() {
for true {
if !utils.TestUnblock() {
log.Warn("Unblock failing, changing IP...")
err := utils.ChangeIPv6()
if err != nil {
log.Error(err.Error())
os.Exit(1)
}
} else {
log.Debug("Unblock OK")
}
time.Sleep(time.Second * 30)
}
}