icinga2/etc/init.d/icinga2.cmake

176 lines
4.1 KiB
CMake
Raw Normal View History

#!/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 5
2013-02-04 12:43:16 +01:00
# Default-Stop: 0 1 6
# 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
2013-11-03 13:45:26 +01:00
DAEMON=@CMAKE_INSTALL_FULL_SBINDIR@/icinga2
ICINGA2_CONFIG_FILE=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2/icinga2.conf
2013-11-25 17:35:44 +01:00
ICINGA2_STATE_DIR=@CMAKE_INSTALL_FULL_LOCALSTATEDIR@
ICINGA2_PID_FILE=$ICINGA2_STATE_DIR/run/icinga2/icinga2.pid
ICINGA2_ERROR_LOG=$ICINGA2_STATE_DIR/log/icinga2/error.log
2014-03-17 18:06:23 +01:00
ICINGA2_LOG=$ICINGA2_STATE_DIR/log/icinga2/icinga2.log
2013-11-03 13:45:26 +01:00
ICINGA2_USER=@ICINGA2_USER@
ICINGA2_GROUP=@ICINGA2_GROUP@
2013-11-25 17:35:44 +01:00
ICINGA2_COMMAND_USER=@ICINGA2_COMMAND_USER@
ICINGA2_COMMAND_GROUP=@ICINGA2_COMMAND_GROUP@
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 [ -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
# Load extra environment variables
if [ -f /etc/sysconfig/icinga ]; then
. /etc/sysconfig/icinga
fi
if [ -f /etc/default/icinga ]; then
. /etc/default/icinga
fi
2013-02-04 12:43:16 +01:00
# Start Icinga 2
start() {
2013-11-25 17:35:44 +01:00
mkdir -p $(dirname -- $ICINGA2_PID_FILE)
chown $ICINGA2_USER:$ICINGA2_GROUP $(dirname -- $ICINGA2_PID_FILE)
2014-03-17 18:06:23 +01:00
chown $ICINGA2_USER:$ICINGA2_GROUP $ICINGA2_PID_FILE
2013-11-25 17:35:44 +01:00
mkdir -p $(dirname -- $ICINGA2_ERROR_LOG)
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $(dirname -- $ICINGA2_ERROR_LOG)
chmod 750 $(dirname -- $ICINGA2_ERROR_LOG)
2014-03-17 18:06:23 +01:00
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_ERROR_LOG $ICINGA2_LOG
2013-11-25 17:35:44 +01:00
mkdir -p $ICINGA2_STATE_DIR/run/icinga2/cmd
chown $ICINGA2_USER:$ICINGA2_COMMAND_GROUP $ICINGA2_STATE_DIR/run/icinga2/cmd
chmod 2755 $ICINGA2_STATE_DIR/run/icinga2/cmd
2013-10-10 14:24:19 +02:00
echo "Starting Icinga 2: "
$DAEMON -c $ICINGA2_CONFIG_FILE -Z -d -e $ICINGA2_ERROR_LOG -u $ICINGA2_USER -g $ICINGA2_GROUP
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."
if [ "x$1" = "xnofail" ]; then
return
else
exit 1
fi
2013-02-04 12:43:16 +01:00
fi
pid=`cat $ICINGA2_PID_FILE`
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
if ! kill -CHLD $pid >/dev/null 2>&1; then
2013-02-04 12:43:16 +01:00
break
fi
printf '.'
sleep 3
2013-02-04 12:43:16 +01:00
done
fi
if kill -CHLD $pid >/dev/null 2>&1; then
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() {
printf "Reloading 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`
if ! kill -HUP $pid >/dev/null 2>&1; then
echo "Failed - Icinga 2 is not running."
else
echo "Done"
fi
}
# Check the Icinga 2 configuration
checkconfig() {
printf "Checking configuration:"
echo "Validating the configuration file:"
if ! $DAEMON -c $ICINGA2_CONFIG_FILE -C -u $ICINGA2_USER -g $ICINGA2_GROUP; then
echo "Not "$1"ing Icinga 2 due to configuration errors."
if [ "x$2" = "xfail" ]; then
exit 1
fi
fi
}
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: "
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-02-14 16:05:58 +01:00
exit 3
2013-02-04 12:43:16 +01:00
fi
}
### main logic ###
case "$1" in
start)
checkconfig start fail
2013-02-04 12:43:16 +01:00
start
;;
stop)
stop
;;
status)
status
2013-02-04 12:43:16 +01:00
;;
restart|condrestart)
checkconfig restart fail
stop nofail
2013-02-04 12:43:16 +01:00
start
;;
reload)
checkconfig reload fail
2013-08-30 14:27:24 +02:00
reload
;;
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}"
2013-02-04 12:43:16 +01:00
exit 1
esac
exit 0