forked from NagiosEnterprises/nagioscore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openrc-init.in
66 lines (55 loc) · 1.93 KB
/
openrc-init.in
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
#!/sbin/openrc-run
# This is a custom variable, and has the following default value if a
# specific config file is not defined by the user.
: ${NAGIOS_CONFIG:="@sysconfdir@/nagios.cfg"}
# These two facilitate the bindir variable substitution below.
prefix=@prefix@
exec_prefix=@exec_prefix@
# The rest are OpenRC variables.
extra_commands="checkconfig"
extra_started_commands="reload"
# We put "--daemon" in command_args and not command_args_background
# because the latter interacts weirdly with the config file argument.
command="@bindir@/nagios"
command_args="--daemon ${NAGIOS_CONFIG}"
pidfile="@lockfile@"
depend(){
# Most daemons don't really *need* the network; they're happy with
# the loopback interface. However, nagios might start generating
# "EVERYTHING IS DOWN" alerts if it starts before the real live
# network comes up.
need net
use logger
after mysql postgresql
}
reload(){
checkconfig || return $?
ebegin "Reloading configuration"
start-stop-daemon --signal HUP --pidfile "${pidfile}"
eend $?
}
checkconfig(){
ebegin "Verifying config files"
# Save the output in case verification fails and errors are printed.
OUTPUT=$( ${command} --verify-config "${NAGIOS_CONFIG}" )
# Save the exit code from the verification so that `echo` doesn't
# clobber it. Then, if verification failed, show its
# output. Otherwise, succeed quietly.
local exit_code=$?
[ $exit_code -ne 0 ] && echo "${OUTPUT}" >&2
eend $exit_code
}
start_pre() {
# Without this, the "start" action will appear to succeed even if
# the config file contains errors, and the daemon fails to start.
# Another approach would be to wait for the PID file to appear, but
# this is fast enough and feels cleaner.
checkconfig || return $?
}
stop_pre() {
# If this is a restart, check to make sure the user's config
# isn't busted before we stop the running daemon.
if [ "${RC_CMD}" = "restart" ] ; then
checkconfig || return $?
fi
}