-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.go
More file actions
148 lines (128 loc) · 3.58 KB
/
main.go
File metadata and controls
148 lines (128 loc) · 3.58 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"fmt"
"hcc/harp/action/grpc/client"
"hcc/harp/action/grpc/server"
"hcc/harp/lib/adaptiveip"
"hcc/harp/lib/config"
"hcc/harp/lib/dhcpd"
"hcc/harp/lib/logger"
"hcc/harp/lib/modprobe"
"hcc/harp/lib/mysql"
"hcc/harp/lib/pid"
"hcc/harp/lib/syscheck"
"innogrid.com/hcloud-classic/hcc_errors"
"os"
"os/signal"
"strconv"
"syscall"
)
func init() {
err := syscheck.CheckRoot()
if err != nil {
fmt.Println(err)
panic(err)
}
harpRunning, harpPID, err := pid.IsHarpRunning()
if err != nil {
fmt.Println(err)
panic(err)
}
if harpRunning {
fmt.Println("harp is already running. (PID: " + strconv.Itoa(harpPID) + ")")
os.Exit(1)
}
err = pid.WriteHarpPID()
if err != nil {
_ = pid.DeleteHarpPID()
fmt.Println(err)
panic(err)
}
err = syscheck.CheckOS()
if err != nil {
fmt.Println("Please run harp module on the Linux machine.")
_ = pid.DeleteHarpPID()
panic(err)
}
err = logger.Init()
if err != nil {
hcc_errors.SetErrLogger(logger.Logger)
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "logger.Init(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
hcc_errors.SetErrLogger(logger.Logger)
err = syscheck.CheckIPLink()
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "syscheck.CheckIPLink(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
err = syscheck.CheckIPTABLES()
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "syscheck.CheckIPTABLES(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
err = syscheck.CheckVnStat()
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "syscheck.CheckVnStat(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
config.Init()
err = client.Init()
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "client.Init(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
err = mysql.Init()
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "mysql.Init(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
_, err = syscheck.CheckIfaceExist(config.AdaptiveIP.ExternalIfaceName)
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "syscheck.CheckIfaceExist(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
_, err = syscheck.CheckIfaceExist(config.AdaptiveIP.InternalIfaceName)
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "syscheck.CheckIfaceExist(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
_, err = syscheck.CheckIfaceExist(config.Timpani.TimpaniTargetIfaceName)
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "syscheck.CheckIfaceExist(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
err = dhcpd.CheckLocalDHCPDConfig()
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "dhcpd.CheckLocalDHCPDConfig(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
err = modprobe.LoadHarpKernelModules()
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "modprobe.InitHarpModules(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
err = adaptiveip.LoadFirewall()
if err != nil {
hcc_errors.NewHccError(hcc_errors.HarpInternalInitFail, "adaptiveip.LoadFirewall(): "+err.Error()).Fatal()
_ = pid.DeleteHarpPID()
}
}
func end() {
mysql.End()
client.End()
logger.End()
_ = pid.DeleteHarpPID()
}
func main() {
// Catch the exit signal
sigChan := make(chan os.Signal)
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigChan
end()
fmt.Println("Exiting harp module...")
os.Exit(0)
}()
server.Init()
}