File rcido2db of Package icinga.3888
#!/bin/sh
#
# Startup script for IDO2DB
#
# /etc/init.d/ido2db
# and its symbolic link
# /usr/sbin/rcido2db
#
### BEGIN INIT INFO
# Provides: ido2db
# Required-Start: $syslog $remote_fs
# Should-Start: mysql
# Required-Stop: $syslog $remote_fs
# Should-Stop: mysql
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Icinga Data Output Utilities
# Description: Automatic startup and shutdown of Icinga IDO2DB.
# IDOUtils is an Icinga addon allowing you to store Icinga data (current status
# information, state history, notification history, etc.) in a MySQL database.
### END INIT INFO
# Note on runlevels:
# 0 - halt/poweroff 6 - reboot
# 1 - single user 2 - multiuser without network exported
# 3 - multiuser w/ network (text mode) 5 - multiuser w/ network and X11 (xdm)
. /etc/rc.status
IDO2DB_BIN="/usr/sbin/ido2db"
IDO2DB_CFG="/etc/icinga/ido2db.cfg"
ICINGA_SYSCONFIG="/etc/sysconfig/icinga"
# grab a config option
get_var() {
if [ -n "$2" ]; then
set -- `grep ^$1 $2 | sed 's@=@ @' | tr -d '[:cntrl:]'`
else
set -- `grep ^$1 "$IDO2DB_CFG" | sed 's@=@ @' | tr -d '[:cntrl:]'`
fi
shift # remove first ARG => search-string
echo $*
}
# check some default files and directories
check_files() {
# remove some perhaps left over files
for file in "$lock_file" "$socket_name"; do
test -e "$file" && rm -f "$file"
done
# create lock directory if it doesn't exist
PIDDIR=$(dirname $lock_file)
test -d "$PIDDIR" || install -d -m755 -o$ido2db_user -g$ido2db_group "$PIDDIR"
}
test -x $IDO2DB_BIN || { echo "$IDO2DB_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
test -r $IDO2DB_CFG || { echo "$IDO2DB_CFG not existing";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
# Check for existence of sysconfig file and read it
test -r "$ICINGA_SYSCONFIG" || { echo "$ICINGA_SYSCONFIG not existing or readable.";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
. "$ICINGA_SYSCONFIG"
# set values for sysconfig vars
if [ -n "$IDO2DB_NICELEVEL" ]; then
NICELEVEL="-n $IDO2DB_NICELEVEL"
else
NICELEVEL="-n 0"
fi
if [ -z "$IDO2DB_TIMEOUT" ]; then
IDO2DB_TIMEOUT=10
fi
#
# get variables from config file
#
lock_file="$(get_var lock_file)"
socket_name="$(get_var socket_name)"
ido2db_user="$(get_var ido2db_user)"
ido2db_group="$(get_var ido2db_group)"
#
# use default values if above check doesn't work
#
: ${lock_file:=/var/run/icinga/ido2db.pid}
: ${socket_name:=/var/run/icinga/ido2db.sock}
: ${ido2db_user:=icinga}
: ${ido2db_group:=icinga}
# Reset status of this service
rc_reset
case "$1" in
start)
echo -n "Starting Ido2db "
IDO2DBPID=$(pidof "$IDO2DB_BIN")
if [ -z "$IDO2DBPID" ]; then
check_files
fi
startproc $NICELEVEL -p "$lock_file" "$IDO2DB_BIN" -c "$IDO2DB_CFG"
# Remember status and be verbose
rc_status -v
;;
stop)
echo -n "Shutting down Ido2db "
if checkproc "$IDO2DB_BIN" ; then
killproc -p "$lock_file" -TERM "$IDO2DB_BIN"
sleep 1
if [ -e "$lock_file" ]; then
echo "Warning - Ido2db did not exit in a timely manner. Waiting..."
while [ -e "$lock_file" ] && [ $IDO2DB_TIMEOUT -gt 0 ] ; do
sleep 1
IDO2DB_TIMEOUT=$(($IDO2DB_TIMEOUT - 1))
echo -n '.'
[ $IDO2DB_TIMEOUT -eq 41 ] && echo
done
fi
if checkproc "$IDO2DB_BIN" ; then
killproc -p "$lock_file" -SIGKILL "$IDO2DB_BIN"
echo -n "Warning: Ido2db killed"
fi
else
echo -n "Ido2db not running"
rc_failed 7
fi
check_files
rc_reset
# Remember status and be verbose
rc_status -v
;;
try-restart)
## Do a restart only if the service was active before.
$0 status
if test $? = 0; then
$0 restart
else
rc_reset # Not running is not a failure.
fi
rc_status
;;
restart)
$0 stop
$0 start
rc_status
;;
reload|force-reload)
echo -n "Reload service Ido2db "
config_check
if [ $? -eq 0 ]; then
echo -n "Passed configuration check - reloading..."
killproc -HUP -p "$lock_file" "$IDO2DB_BIN"
else
echo "- Error in configuration files"
echo -n "- aborting reload - please read $IDO2DB_CFG_ERR_LOG"
rc_failed
fi
rc_status -v
;;
status)
echo -n "Checking for Ido2db "
checkproc -p "$lock_file" "$IDO2DB_BIN"
rc_status -v
;;
check)
echo -n "Starting configuration check "
config_check
if [ $? -eq 0 ]; then
echo "- passed configuration check"
test -f $IDO2DB_CFG_ERR_LOG && rm $IDO2DB_CFG_ERR_LOG
rc_reset
else
echo "- detected Error in configuration files"
echo "Please read $IDO2DB_CFG_ERR_LOG"
rc_failed
fi
rc_status -v
;;
check_verbose)
echo "Running verbose configuration check..."
config_check verbose
exitcode=$?
cat "$IDO2DB_CFG_ERR_LOG"
rc_failed $exitcode
rc_status -v
rc_exit
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|reload|check|check_verbose}"
exit 1
;;
esac
rc_exit