2013-05-03 13:39:31 +02:00
|
|
|
#!/bin/sh
|
2013-02-04 12:43:16 +01:00
|
|
|
#
|
|
|
|
# chkconfig: 35 90 12
|
|
|
|
# description: Icinga 2
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: icinga2
|
|
|
|
# Required-Start: $remote_fs $syslog
|
|
|
|
# Required-Stop: $remote_fs $syslog
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: Start Icinga 2 at boot time
|
|
|
|
# Description: Icinga 2
|
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
prefix=@prefix@
|
|
|
|
exec_prefix=@exec_prefix@
|
|
|
|
sbindir=@sbindir@
|
2013-08-16 14:50:01 +02:00
|
|
|
bindir=@bindir@
|
2013-02-04 12:43:16 +01:00
|
|
|
sysconfdir=@sysconfdir@
|
|
|
|
localstatedir=@localstatedir@
|
|
|
|
|
2013-08-16 14:50:01 +02:00
|
|
|
DAEMON=$bindir/icinga2
|
2013-02-04 12:43:16 +01:00
|
|
|
ICINGA2_CONFIG_FILE=$sysconfdir/icinga2/icinga2.conf
|
2013-03-10 13:55:28 +01:00
|
|
|
ICINGA2_PID_FILE=$localstatedir/run/icinga2/icinga2.pid
|
2013-03-12 11:48:45 +01:00
|
|
|
ICINGA2_ERROR_LOG=$localstatedir/log/icinga2/error.log
|
2013-02-04 12:43:16 +01:00
|
|
|
|
|
|
|
test -x $DAEMON || exit 0
|
|
|
|
|
|
|
|
if [ ! -e $ICINGA2_CONFIG_FILE ]; then
|
|
|
|
echo "Config file '$ICINGA2_CONFIG_FILE' does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get function from functions library
|
|
|
|
if [ -e /etc/init.d/functions ]; then
|
|
|
|
. /etc/init.d/functions
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Start Icinga 2
|
|
|
|
start() {
|
2013-03-12 09:58:27 +01:00
|
|
|
mkdir -p `dirname -- $ICINGA2_PID_FILE`
|
2013-03-12 11:48:45 +01:00
|
|
|
mkdir -p `dirname -- $ICINGA2_ERROR_LOG`
|
|
|
|
|
|
|
|
echo "Validating the configuration file:"
|
|
|
|
if ! $DAEMON -c $ICINGA2_CONFIG_FILE -v; then
|
|
|
|
echo "Not starting Icinga 2 due to configuration errors."
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-03-12 09:58:27 +01:00
|
|
|
|
2013-02-04 12:43:16 +01:00
|
|
|
printf "Starting Icinga 2: "
|
2013-05-03 13:39:31 +02:00
|
|
|
$DAEMON -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG
|
2013-03-12 11:48:45 +01:00
|
|
|
|
2013-02-04 12:43:16 +01:00
|
|
|
echo "Done"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
# Restart Icinga 2
|
|
|
|
stop() {
|
|
|
|
printf "Stopping Icinga 2: "
|
|
|
|
if [ ! -e $ICINGA2_PID_FILE ]; then
|
|
|
|
echo "The PID file '$ICINGA2_PID_FILE' does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
pid=`cat $ICINGA2_PID_FILE`
|
|
|
|
|
2013-03-12 11:48:45 +01:00
|
|
|
if kill -INT $pid >/dev/null 2>&1; then
|
2013-02-04 12:43:16 +01:00
|
|
|
for i in 1 2 3 4 5 6 7 8 9 10; do
|
2013-03-12 16:16:49 +01:00
|
|
|
if ! kill -CHLD $pid >/dev/null 2>&1; then
|
2013-02-04 12:43:16 +01:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf '.'
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
fi
|
2013-03-12 11:48:45 +01:00
|
|
|
|
2013-03-12 16:16:49 +01:00
|
|
|
if kill -CHLD $pid >/dev/null 2>&1; then
|
2013-03-12 11:48:45 +01:00
|
|
|
kill -KILL $pid
|
|
|
|
fi
|
|
|
|
|
2013-02-04 12:43:16 +01:00
|
|
|
echo "Done"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Print status for Icinga 2
|
|
|
|
status() {
|
|
|
|
printf "Icinga 2 status: "
|
|
|
|
|
|
|
|
pid=`cat $ICINGA2_PID_FILE`
|
2013-05-03 14:49:21 +02:00
|
|
|
if kill -CHLD $pid >/dev/null 2>&1; then
|
2013-02-04 12:43:16 +01:00
|
|
|
echo "Running"
|
|
|
|
else
|
|
|
|
echo "Not running"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
### main logic ###
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status FOO
|
|
|
|
;;
|
|
|
|
restart|condrestart)
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
*)
|
2013-08-20 11:06:04 +02:00
|
|
|
echo $"Usage: $0 {start|stop|restart|status}"
|
2013-02-04 12:43:16 +01:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
exit 0
|