Last active
January 3, 2016 12:39
-
-
Save mabrizio/8463854 to your computer and use it in GitHub Desktop.
Nagios service startup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Nagios Startup script for the Nagios monitoring daemon | |
# | |
# chkconfig: - 85 15 | |
# description: Nagios is a service monitoring system | |
# processname: nagios | |
# config: /etc/nagios/nagios.cfg | |
# pidfile: /var/nagios/nagios.pid | |
# | |
### BEGIN INIT INFO | |
# Provides: nagios | |
# Required-Start: $local_fs $syslog $network | |
# Required-Stop: $local_fs $syslog $network | |
# Short-Description: start and stop Nagios monitoring server | |
# Description: Nagios is is a service monitoring system | |
### END INIT INFO | |
# Source function library. | |
# . /etc/rc.d/init.d/functions | |
. /lib/lsb/init-functions | |
prefix="/usr/local/nagios" | |
exec_prefix="${prefix}" | |
exec="${exec_prefix}/bin/nagios" | |
prog="nagios" | |
config="${prefix}/etc/nagios.cfg" | |
pidfile="${prefix}/var/nagios.lock" | |
user="nagios" | |
group="nagios" | |
checkconfig="false" | |
ramdiskdir="/var/nagios/ramcache" | |
test -e /etc/sysconfig/$prog && . /etc/sysconfig/$prog | |
lockfile=/var/lock/$prog | |
USE_RAMDISK=${USE_RAMDISK:-0} | |
if test "$USE_RAMDISK" -ne 0 && test "$RAMDISK_SIZE"X != "X"; then | |
ramdisk=`mount |grep "$ramdiskdir type tmpfs"` | |
if [ "$ramdisk"X == "X" ]; then | |
mkdir -p -m 0755 $ramdiskdir | |
mount -t tmpfs -o size=${RAMDISK_SIZE}m tmpfs $ramdiskdir | |
mkdir -p -m 0755 $ramdiskdir/checkresults | |
chown -R $user:$group $ramdiskdir | |
fi | |
fi | |
check_config() { | |
TMPFILE="/tmp/.configtest.$$" | |
/usr/sbin/service nagios configtest > "$TMPFILE" | |
WARN=`grep ^"Total Warnings:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g` | |
ERR=`grep ^"Total Errors:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g` | |
if test "$WARN" = "0" && test "${ERR}" = "0"; then | |
echo "OK - Configuration check verified" > /var/run/nagios.configtest | |
chmod 0644 /var/run/nagios.configtest | |
/bin/rm "$TMPFILE" | |
return 0 | |
else | |
# We'll write out the errors to a file we can have a | |
# script watching for | |
echo "WARNING: Errors in config files - see log for details: $TMPFILE" > /var/run/nagios.configtest | |
egrep -i "(^warning|^error)" "$TMPFILE" >> /var/run/nagios.configtest | |
chmod 0644 /var/run/nagios.configtest | |
cat "$TMPFILE" | |
exit 8 | |
fi | |
} | |
start() { | |
test -x $exec || exit 5 | |
test -f $config || exit 6 | |
if test "$checkconfig" = "false"; then | |
check_config | |
fi | |
echo -n $"Starting $prog: " | |
# We need to _make sure_ the precache is there and verified | |
# Raise priority to make it run better | |
daemon --user=$user -- $exec -d $config | |
#touch $lockfile | |
retval=$? | |
echo | |
test $retval -eq 0 && touch $lockfile | |
return $retval | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
killproc -p ${pidfile} $exec | |
retval=$? | |
echo | |
test $retval -eq 0 && rm -f $lockfile | |
return $retval | |
} | |
restart() { | |
check_config | |
checkconfig="true" | |
stop | |
start | |
} | |
reload() { | |
echo -n $"Reloading $prog: " | |
killproc -p ${pidfile} $exec -HUP | |
RETVAL=$? | |
echo | |
} | |
force_reload() { | |
restart | |
} | |
case "$1" in | |
start) | |
status_of_proc $prog && exit 0 | |
$1 | |
;; | |
stop) | |
status_of_proc $prog|| exit 0 | |
$1 | |
;; | |
restart) | |
$1 | |
;; | |
reload) | |
status_of_proc $prog || exit 7 | |
$1 | |
;; | |
force-reload) | |
force_reload | |
;; | |
status) | |
status_of_proc $prog | |
;; | |
condrestart|try-restart) | |
status_of_proc $prog|| exit 0 | |
restart | |
;; | |
configtest) | |
$nice su -s /bin/bash - nagios -c "$corelimit >/dev/null 2>&1 ; $exec -vp $config" | |
RETVAL=$? | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" | |
exit 2 | |
esac | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment