blob: 871fadd762f8ea57b841e1fcba1a8d9ac5f62874 (
plain)
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
|
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: nagios
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable nagios:
# nagios_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable nagios.
# nagios_precache (bool): Set to "NO" by default.
# Set it to "YES" to enable pre-caching.
# nagios_flags (str): Set to "" by default.
# nagios_configfile (str): Set to "%%ETCDIR%%/nagios.cfg" by default.
#
. /etc/rc.subr
name=nagios
rcvar=nagios_enable
load_rc_config "${name}"
start_precmd=start_precmd
stop_postcmd=stop_postcmd
restart_precmd=nagios_checkconfig
reload_precmd=reload_precmd
configtest_cmd=nagios_checkconfig
sig_reload=HUP
nagios_enable=${nagios_enable:-"NO"}
nagios_program=${nagios_program:-"%%PREFIX%%/bin/nagios"} # Path to named, if you want a different one.
command_args=${command_args:-"-d"}
extra_commands=${extra_commands:-"reload configtest"}
pidfile=${pidfile:-"%%NAGIOSDIR%%/nagios.lock"}
nagios_user=${nagios_user:-"%%NAGIOSUSER%%"}
nagios_group=${nagios_group:-"%%NAGIOSGROUP%%"}
nagios_configfile=${nagios_configfile:-"%%ETCDIR%%/nagios.cfg"}
nagios_precache=${nagios_precache:-"NO"}
required_files="${nagios_configfile}"
command_args="${command_args} ${nagios_configfile}"
nagios_cacheconfig()
{
if ! checkyesno nagios_precache; then
return 0
fi
echo -n "Pre-Caching nagios configuration: "
${command} -pv ${nagios_configfile} 2>&1 >/dev/null
if [ $? != 0 ]; then
echo "FAILED"
${command} -v ${nagios_configfile}
return 1
else
command_args="-u -x ${command_args}"
echo "OK"
fi
}
nagios_checkconfig()
{
echo -n "Performing sanity check of nagios configuration: "
${command} -v ${nagios_configfile} 2>&1 >/dev/null
if [ $? != 0 ]; then
echo "FAILED"
${command} -v ${nagios_configfile}
return 1
else
echo "OK"
fi
}
reload_precmd()
{
if ! nagios_checkconfig; then
return 1
fi
if ! nagios_cacheconfig; then
return 1
fi
}
start_precmd()
{
if ! nagios_checkconfig; then
return 1
fi
if ! nagios_cacheconfig; then
return 1
fi
su -m "${nagios_user}" -c "touch \"%%NAGIOSDIR%%/nagios.log\" \"%%NAGIOSDIR%%/status.sav\""
rm -f "%%NAGIOSDIR%%/rw/nagios.cmd"
}
stop_postcmd()
{
rm -f "%%NAGIOSDIR%%/nagios.tmp" "%%NAGIOSDIR%%/rw/nagios.cmd"
}
run_rc_command "$1"
|