-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenrc_icinga2
executable file
·138 lines (112 loc) · 2.93 KB
/
openrc_icinga2
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
#!/usr/bin/openrc-run
description="Icinga 2 is a monitoring and management system for hosts, services and networks."
extra_commands="checkconfig"
extra_started_commands="reload"
depend() {
need net
after network
}
start_pre() {
if [ ! -e $ICINGA2_CONFIG_FILE ]; then
eerror "Config file '$ICINGA2_CONFIG_FILE' does not exist."
exit 6
fi
getent passwd $ICINGA2_USER >/dev/null 2>&1 || (echo "Icinga user '$ICINGA2_USER' does not exist. Exiting." && exit 6)
getent group $ICINGA2_GROUP >/dev/null 2>&1 || (echo "Icinga group '$ICINGA2_GROUP' does not exist. Exiting." && exit 6)
getent group $ICINGA2_COMMAND_GROUP >/dev/null 2>&1 || (echo "Icinga command group '$ICINGA2_COMMAND_GROUP' does not exist. Exiting." && exit 6)
if [ "${RC_CMD}" = "restart" ] ; then
checkconfig || return $?
fi
}
# Start Icinga 2
start() {
ebegin "Starting Icinga 2: "
/usr/lib/icinga2/prepare-dirs "$SYSCONFIGFILE"
if ! $DAEMON daemon --config $ICINGA2_CONFIG_FILE --daemonize --errorlog $ICINGA2_ERROR_LOG > $ICINGA2_STARTUP_LOG 2>&1
then
eerror "Error starting Icinga. Check '$ICINGA2_STARTUP_LOG' for details."
eend 1
else
einfo "Done"
fi
}
# Restart Icinga 2
stop() {
ebegin "Stopping Icinga 2: "
if [ ! -e $ICINGA2_PID_FILE ]
then
eerror "The PID file '$ICINGA2_PID_FILE' does not exist."
if [ "x$1" = "xnofail" ]
then
return
else
eend 7
fi
fi
pid=$(cat $ICINGA2_PID_FILE)
if icinga2 internal signal -s SIGINT -p $pid >/dev/null 2>&1
then
for i in $(seq 1 10); do
if ! icinga2 internal signal -s SIGCHLD -p $pid >/dev/null 2>&1
then
break
fi
sleep 3
done
fi
if icinga2 internal signal -s SIGCHLD -p $pid >/dev/null 2>&1
then
icinga2 internal signal -s SIGKILL -p $pid >/dev/null 2>&1
fi
eend $?
}
# Reload Icinga 2
reload() {
checkconfig || return $?
ebegin "Reloading ${RC_SVCNAME}"
exec /usr/lib/icinga2/safe-reload "$SYSCONFIGFILE"
eend $?
}
# Check the Icinga 2 configuration
checkconfig() {
ebegin "Checking configuration: "
if ! $DAEMON daemon --config $ICINGA2_CONFIG_FILE --validate > $ICINGA2_STARTUP_LOG 2>&1
then
if [ "x$1" = "x" ]
then
cat $ICINGA2_STARTUP_LOG
einfo "Icinga 2 detected configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
eend 1
else
einfo "Not "$1"ing Icinga 2 due to configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
if [ "x$2" = "xfail" ]
then
eend 1
fi
fi
fi
einfo "Done"
# no arguments requires full output
if [ "x$1" = "x" ]
then
cat $ICINGA2_STARTUP_LOG
fi
}
# Print status for Icinga 2
status() {
ebegin "Icinga 2 status: "
if [ ! -e $ICINGA2_PID_FILE ]
then
eerror "Not running"
eend 3
fi
pid=`cat $ICINGA2_PID_FILE`
if icinga2 internal signal -s SIGCHLD -p $pid >/dev/null 2>&1
then
einfo "Running"
else
eerror "Not running"
eend 3
fi
}
# exit 0