2014-05-18 23:14:30 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# This script prepares directories and files needed for running Icinga2
|
|
|
|
#
|
|
|
|
|
|
|
|
# load system specific defines
|
2014-06-15 19:47:27 +02:00
|
|
|
SYSCONFIGFILE=$1
|
|
|
|
if [ -f "$SYSCONFIGFILE" ]; then
|
|
|
|
. $SYSCONFIGFILE
|
2014-05-18 23:14:30 +02:00
|
|
|
else
|
2014-06-15 19:47:27 +02:00
|
|
|
echo "Error: You need to supply the path to the Icinga2 sysconfig file as parameter."
|
2014-05-18 23:14:30 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-11-25 18:42:13 +01:00
|
|
|
|
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
|
|
|
ICINGA2_GROUP=`$DAEMON variable get --current RunAsGroup`
|
2014-11-25 18:42:13 +01:00
|
|
|
if [ $? != 0 ]; then
|
|
|
|
echo "Could not fetch RunAsGroup variable. Error '$ICINGA2_GROUP'. Exiting."
|
|
|
|
exit 6
|
|
|
|
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-10-20 21:41:04 +02:00
|
|
|
|
2017-11-29 13:56:10 +01:00
|
|
|
if [ ! -e "$ICINGA2_RUN_DIR"/icinga2 ]; then
|
|
|
|
mkdir "$ICINGA2_RUN_DIR"/icinga2
|
|
|
|
mkdir "$ICINGA2_RUN_DIR"/icinga2/cmd
|
|
|
|
chmod 755 "$ICINGA2_RUN_DIR"/icinga2
|
|
|
|
chmod 2750 "$ICINGA2_RUN_DIR"/icinga2/cmd
|
|
|
|
chown -R $ICINGA2_USER:$ICINGA2_COMMAND_GROUP "$ICINGA2_RUN_DIR"/icinga2
|
2014-05-18 23:14:30 +02:00
|
|
|
fi
|
|
|
|
|
2017-11-29 13:56:10 +01:00
|
|
|
# Could be undefined in installations where sysconf is not overridden on upgrade
|
|
|
|
if [ -z "$ICINGA2_LOG_DIR" ]; then
|
|
|
|
$ICINGA2_LOG_DIR=$(dirname -- "$ICINGA2_LOG")
|
2014-05-18 23:14:30 +02:00
|
|
|
fi
|
|
|
|
|
2017-11-29 13:56:10 +01:00
|
|
|
test -e "$ICINGA2_LOG_DIR" || install -m 750 -o $ICINGA2_USER -g $ICINGA2_COMMAND_GROUP -d "$ICINGA2_LOG_DIR"
|
|
|
|
|
2015-11-18 20:18:04 +01:00
|
|
|
if type restorecon >/dev/null 2>&1; then
|
2017-11-29 13:56:10 +01:00
|
|
|
restorecon -R "$ICINGA2_RUN_DIR"/icinga2/
|
2015-03-17 19:51:54 +01:00
|
|
|
fi
|
2017-07-01 13:59:58 +02:00
|
|
|
|
2017-09-22 09:31:05 +02:00
|
|
|
# Add a fallback if the user did not specify this directory in the sysconfig file
|
|
|
|
if [ -z "$ICINGA2_CACHE_DIR" ]; then
|
2017-11-29 13:56:10 +01:00
|
|
|
ICINGA2_CACHE_DIR="$ICINGA2_STATE_DIR"/cache/icinga2
|
2017-09-22 09:31:05 +02:00
|
|
|
fi
|
2017-11-29 13:56:10 +01:00
|
|
|
|
|
|
|
test -e "$ICINGA2_CACHE_DIR" || install -m 750 -o $ICINGA2_USER -g $ICINGA2_COMMAND_GROUP -d "$ICINGA2_CACHE_DIR"
|