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
|
2014-04-29 17:26:39 +02:00
|
|
|
# Should-Start: mysql postgresql
|
|
|
|
# Should-Stop: mysql postgresql
|
2013-11-27 14:10:46 +01:00
|
|
|
# Default-Start: 2 3 5
|
2013-02-04 12:43:16 +01:00
|
|
|
# Default-Stop: 0 1 6
|
2013-08-16 17:06:37 +02:00
|
|
|
# Short-Description: icinga2 host/service/network monitoring and management system
|
|
|
|
# Description: Icinga 2 is a monitoring and management system for hosts, services and networks.
|
2013-02-04 12:43:16 +01:00
|
|
|
### END INIT INFO
|
|
|
|
|
2014-05-18 22:47:27 +02:00
|
|
|
# load system specific defines
|
2014-06-15 19:47:27 +02:00
|
|
|
SYSCONFIGFILE=@ICINGA2_SYSCONFIGFILE@
|
|
|
|
if [ -f $SYSCONFIGFILE ]; then
|
|
|
|
. $SYSCONFIGFILE
|
2014-05-18 22:47:27 +02:00
|
|
|
else
|
2014-06-15 19:47:27 +02:00
|
|
|
echo "Can't load system specific defines from $SYSCONFIGFILE."
|
2014-09-02 13:40:33 +02:00
|
|
|
exit 6
|
2014-05-18 22:47:27 +02:00
|
|
|
fi
|
2013-02-04 12:43:16 +01:00
|
|
|
|
2014-09-02 13:40:33 +02:00
|
|
|
test -x $DAEMON || exit 5
|
2013-02-04 12:43:16 +01:00
|
|
|
|
2014-11-25 18:42:13 +01:00
|
|
|
if [ ! -e $ICINGA2_CONFIG_FILE ]; then
|
|
|
|
echo "Config file '$ICINGA2_CONFIG_FILE' does not exist."
|
|
|
|
exit 6
|
|
|
|
fi
|
|
|
|
|
2014-10-20 21:41:04 +02:00
|
|
|
ICINGA2_USER=`$DAEMON variable get --current RunAsUser`
|
2014-11-25 18:42:13 +01:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Could not fetch RunAsUser variable. Error '$ICINGA2_USER'. Exiting."
|
|
|
|
exit 6
|
|
|
|
fi
|
2014-10-20 21:41:04 +02:00
|
|
|
|
2014-11-25 18:42:13 +01:00
|
|
|
ICINGA2_GROUP=`$DAEMON variable get --current RunAsGroup`
|
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Could not fetch RunAsGroup variable. Error '$ICINGA2_GROUP'. Exiting."
|
2014-09-02 13:40:33 +02:00
|
|
|
exit 6
|
2013-02-04 12:43:16 +01:00
|
|
|
fi
|
|
|
|
|
2014-11-26 06:40:24 +01:00
|
|
|
getent passwd $ICINGA2_USER >/dev/null 2>&1 || (echo "Icinga user '$ICINGA2_USER' does not exist. Exiting." && exit 6)
|
|
|
|
getent group $ICINGA2_GROUP >/dev/null 2>&1 || (echo "Icinga group '$ICINGA2_GROUP' does not exist. Exiting." && exit 6)
|
|
|
|
getent group $ICINGA2_COMMAND_GROUP >/dev/null 2>&1 || (echo "Icinga command group '$ICINGA2_COMMAND_GROUP' does not exist. Exiting." && exit 6)
|
2014-11-25 18:42:13 +01:00
|
|
|
|
2013-02-04 12:43:16 +01:00
|
|
|
# Get function from functions library
|
2013-09-27 19:41:08 +02:00
|
|
|
if [ -f /etc/rc.d/init.d/functions ]; then
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
elif [ -f /etc/init.d/functions ]; then
|
2013-02-04 12:43:16 +01:00
|
|
|
. /etc/init.d/functions
|
|
|
|
fi
|
|
|
|
|
2013-09-27 19:41:08 +02:00
|
|
|
# Load extra environment variables
|
2014-06-15 19:47:27 +02:00
|
|
|
if [ -f /etc/default/icinga2 ]; then
|
|
|
|
. /etc/default/icinga2
|
2013-09-27 19:41:08 +02:00
|
|
|
fi
|
|
|
|
|
2014-06-12 16:05:45 +02:00
|
|
|
# Start Icinga 2
|
|
|
|
start() {
|
|
|
|
printf "Starting Icinga 2: "
|
2014-11-27 14:33:26 +01:00
|
|
|
@CMAKE_INSTALL_PREFIX@/lib/icinga2/prepare-dirs $SYSCONFIGFILE
|
2013-03-12 11:48:45 +01:00
|
|
|
|
2014-10-13 13:43:05 +02:00
|
|
|
if ! $DAEMON daemon -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG > $ICINGA2_STARTUP_LOG 2>&1; then
|
2014-06-12 16:05:45 +02:00
|
|
|
echo "Error starting Icinga. Check '$ICINGA2_STARTUP_LOG' for details."
|
2014-04-14 00:16:48 +02:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "Done"
|
|
|
|
fi
|
2013-02-04 12:43:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Restart Icinga 2
|
|
|
|
stop() {
|
|
|
|
printf "Stopping Icinga 2: "
|
2014-06-12 16:05:45 +02:00
|
|
|
|
2013-02-04 12:43:16 +01:00
|
|
|
if [ ! -e $ICINGA2_PID_FILE ]; then
|
|
|
|
echo "The PID file '$ICINGA2_PID_FILE' does not exist."
|
2013-10-14 18:02:37 +02:00
|
|
|
if [ "x$1" = "xnofail" ]; then
|
|
|
|
return
|
|
|
|
else
|
2014-09-02 13:48:48 +02:00
|
|
|
exit 7
|
2013-10-14 18:02:37 +02:00
|
|
|
fi
|
2013-02-04 12:43:16 +01:00
|
|
|
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 '.'
|
|
|
|
|
2014-03-17 09:04:19 +01:00
|
|
|
sleep 3
|
2013-02-04 12:43:16 +01:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2013-08-30 14:27:24 +02:00
|
|
|
# Reload Icinga 2
|
|
|
|
reload() {
|
2014-12-11 09:27:31 +01:00
|
|
|
exec @CMAKE_INSTALL_PREFIX@/lib/icinga2/safe-reload $SYSCONFIGFILE
|
2013-08-30 14:27:24 +02:00
|
|
|
}
|
|
|
|
|
2013-09-25 12:42:53 +02:00
|
|
|
# Check the Icinga 2 configuration
|
|
|
|
checkconfig() {
|
2014-06-12 16:05:45 +02:00
|
|
|
printf "Checking configuration: "
|
2013-09-25 12:42:53 +02:00
|
|
|
|
2014-10-13 13:43:05 +02:00
|
|
|
if ! $DAEMON daemon -c $ICINGA2_CONFIG_FILE -C > $ICINGA2_STARTUP_LOG 2>&1; then
|
2014-05-22 17:26:56 +02:00
|
|
|
if [ "x$1" = "x" ]; then
|
2014-06-12 16:05:45 +02:00
|
|
|
cat $ICINGA2_STARTUP_LOG
|
|
|
|
echo "Icinga 2 detected configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
|
2014-05-22 17:26:56 +02:00
|
|
|
exit 1
|
|
|
|
else
|
2014-06-12 16:05:45 +02:00
|
|
|
echo "Not "$1"ing Icinga 2 due to configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
|
2014-05-22 17:26:56 +02:00
|
|
|
if [ "x$2" = "xfail" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
2014-03-16 23:26:47 +01:00
|
|
|
fi
|
2014-06-12 16:05:45 +02:00
|
|
|
|
|
|
|
echo "Done"
|
|
|
|
# no arguments requires full output
|
|
|
|
if [ "x$1" = "x" ]; then
|
|
|
|
cat $ICINGA2_STARTUP_LOG
|
|
|
|
fi
|
2013-09-25 12:42:53 +02:00
|
|
|
}
|
2013-08-30 14:27:24 +02:00
|
|
|
|
2013-02-04 12:43:16 +01:00
|
|
|
# Print status for Icinga 2
|
|
|
|
status() {
|
|
|
|
printf "Icinga 2 status: "
|
|
|
|
|
2014-09-02 13:48:48 +02:00
|
|
|
if [ ! -e $ICINGA2_PID_FILE ]; then
|
|
|
|
echo "Not running"
|
|
|
|
exit 7
|
|
|
|
fi
|
|
|
|
|
2013-02-04 12:43:16 +01:00
|
|
|
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"
|
2014-09-02 13:40:33 +02:00
|
|
|
exit 7
|
2013-02-04 12:43:16 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
### main logic ###
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2014-03-16 23:26:47 +01:00
|
|
|
checkconfig start fail
|
2013-02-04 12:43:16 +01:00
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
status)
|
2013-10-14 18:02:37 +02:00
|
|
|
status
|
2013-02-04 12:43:16 +01:00
|
|
|
;;
|
|
|
|
restart|condrestart)
|
2014-03-16 23:26:47 +01:00
|
|
|
checkconfig restart fail
|
2013-10-14 18:02:37 +02:00
|
|
|
stop nofail
|
2013-02-04 12:43:16 +01:00
|
|
|
start
|
|
|
|
;;
|
2013-09-25 12:42:53 +02:00
|
|
|
reload)
|
2013-08-30 14:27:24 +02:00
|
|
|
reload
|
|
|
|
;;
|
2013-09-25 12:42:53 +02:00
|
|
|
checkconfig)
|
|
|
|
checkconfig
|
|
|
|
;;
|
2013-02-04 12:43:16 +01:00
|
|
|
*)
|
2013-09-27 13:56:11 +02:00
|
|
|
echo "Usage: $0 {start|stop|restart|reload|checkconfig|status}"
|
2014-09-02 13:40:33 +02:00
|
|
|
exit 3
|
2013-02-04 12:43:16 +01:00
|
|
|
esac
|
|
|
|
exit 0
|