mirror of https://github.com/Icinga/icinga2.git
commit
a68d774f78
|
@ -24,45 +24,56 @@ fi
|
|||
|
||||
# load system specific defines
|
||||
SYSCONFIGFILE=@ICINGA2_SYSCONFIGFILE@
|
||||
if [ -f $SYSCONFIGFILE ]; then
|
||||
. $SYSCONFIGFILE
|
||||
if [ -f "$SYSCONFIGFILE" ]; then
|
||||
. "$SYSCONFIGFILE"
|
||||
else
|
||||
echo "Couldn't load system specific defines from $SYSCONFIGFILE. Using defaults."
|
||||
fi
|
||||
|
||||
# Set defaults, to overwrite see "@ICINGA2_SYSCONFIGFILE@"
|
||||
|
||||
: ${ICINGA2_USER:="@ICINGA2_USER@"}
|
||||
: ${ICINGA2_GROUP:="@ICINGA2_GROUP@"}
|
||||
: ${ICINGA2_COMMAND_GROUP:="@ICINGA2_COMMAND_GROUP@"}
|
||||
: ${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"}
|
||||
: ${ICINGA2_CONFIG_FILE:="@ICINGA2_CONFIGDIR@/icinga2.conf"}
|
||||
: ${ICINGA2_ERROR_LOG:=@ICINGA2_LOGDIR@/error.log}
|
||||
: ${ICINGA2_STARTUP_LOG:=@ICINGA2_LOGDIR@/startup.log}
|
||||
: ${ICINGA2_PID_FILE:="@ICINGA2_INITRUNDIR@/icinga2.pid"}
|
||||
: "${ICINGA2_USER:="@ICINGA2_USER@"}"
|
||||
: "${ICINGA2_GROUP:="@ICINGA2_GROUP@"}"
|
||||
: "${ICINGA2_COMMAND_GROUP:="@ICINGA2_COMMAND_GROUP@"}"
|
||||
: "${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"}"
|
||||
: "${ICINGA2_CONFIG_FILE:="@ICINGA2_CONFIGDIR@/icinga2.conf"}"
|
||||
: "${ICINGA2_ERROR_LOG:=@ICINGA2_LOGDIR@/error.log}"
|
||||
: "${ICINGA2_STARTUP_LOG:=@ICINGA2_LOGDIR@/startup.log}"
|
||||
: "${ICINGA2_PID_FILE:="@ICINGA2_INITRUNDIR@/icinga2.pid"}"
|
||||
|
||||
# Load extra environment variables
|
||||
if [ -f /etc/default/icinga2 ]; then
|
||||
. /etc/default/icinga2
|
||||
fi
|
||||
|
||||
test -x $DAEMON || exit 5
|
||||
test -x "$DAEMON" || exit 5
|
||||
|
||||
if [ ! -e $ICINGA2_CONFIG_FILE ]; then
|
||||
if [ ! -e "$ICINGA2_CONFIG_FILE" ]; then
|
||||
echo "Config file '$ICINGA2_CONFIG_FILE' does not exist."
|
||||
exit 6
|
||||
fi
|
||||
|
||||
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)
|
||||
if ! getent passwd "$ICINGA2_USER" >/dev/null 2>&1; then
|
||||
echo "Icinga user '$ICINGA2_USER' does not exist. Exiting."
|
||||
exit 6
|
||||
fi
|
||||
|
||||
if ! getent group "$ICINGA2_GROUP" >/dev/null 2>&1; then
|
||||
echo "Icinga group '$ICINGA2_GROUP' does not exist. Exiting."
|
||||
exit 6
|
||||
fi
|
||||
|
||||
if ! getent group "$ICINGA2_COMMAND_GROUP" >/dev/null 2>&1; then
|
||||
echo "Icinga command group '$ICINGA2_COMMAND_GROUP' does not exist. Exiting."
|
||||
exit 6
|
||||
fi
|
||||
|
||||
# Start Icinga 2
|
||||
start() {
|
||||
printf "Starting Icinga 2: "
|
||||
@CMAKE_INSTALL_PREFIX@/lib/icinga2/prepare-dirs "$SYSCONFIGFILE"
|
||||
|
||||
if ! $DAEMON daemon -c $ICINGA2_CONFIG_FILE -d -e $ICINGA2_ERROR_LOG > $ICINGA2_STARTUP_LOG 2>&1; then
|
||||
if ! "$DAEMON" daemon -c "$ICINGA2_CONFIG_FILE" -d -e "$ICINGA2_ERROR_LOG" > "$ICINGA2_STARTUP_LOG" 2>&1; then
|
||||
echo "Error starting Icinga. Check '$ICINGA2_STARTUP_LOG' for details."
|
||||
exit 1
|
||||
else
|
||||
|
@ -74,7 +85,7 @@ start() {
|
|||
stop() {
|
||||
printf "Stopping Icinga 2: "
|
||||
|
||||
if [ ! -e $ICINGA2_PID_FILE ]; then
|
||||
if [ ! -e "$ICINGA2_PID_FILE" ]; then
|
||||
echo "The PID file '$ICINGA2_PID_FILE' does not exist."
|
||||
if [ "x$1" = "xnofail" ]; then
|
||||
return
|
||||
|
@ -83,11 +94,11 @@ stop() {
|
|||
fi
|
||||
fi
|
||||
|
||||
pid=`cat $ICINGA2_PID_FILE`
|
||||
pid=`cat "$ICINGA2_PID_FILE"`
|
||||
|
||||
if icinga2 internal signal -s SIGINT -p $pid >/dev/null 2>&1; then
|
||||
if icinga2 internal signal -s SIGINT -p "$pid" >/dev/null 2>&1; then
|
||||
for i in 1 2 3 4 5 6 7 8 9 10; do
|
||||
if ! icinga2 internal signal -s SIGCHLD -p $pid >/dev/null 2>&1; then
|
||||
if ! icinga2 internal signal -s SIGCHLD -p "$pid" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
|
||||
|
@ -96,8 +107,8 @@ stop() {
|
|||
done
|
||||
fi
|
||||
|
||||
if icinga2 internal signal -s SIGCHLD -p $pid >/dev/null 2>&1; then
|
||||
icinga2 internal signal -s SIGKILL -p $pid >/dev/null 2>&1
|
||||
if icinga2 internal signal -s SIGCHLD -p "$pid" >/dev/null 2>&1; then
|
||||
icinga2 internal signal -s SIGKILL -p "$pid" >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
echo "Done"
|
||||
|
@ -112,13 +123,13 @@ reload() {
|
|||
checkconfig() {
|
||||
printf "Checking configuration: "
|
||||
|
||||
if ! $DAEMON daemon -c $ICINGA2_CONFIG_FILE -C > $ICINGA2_STARTUP_LOG 2>&1; then
|
||||
if ! "$DAEMON" daemon -c "$ICINGA2_CONFIG_FILE" -C > "$ICINGA2_STARTUP_LOG" 2>&1; then
|
||||
if [ "x$1" = "x" ]; then
|
||||
cat $ICINGA2_STARTUP_LOG
|
||||
cat "$ICINGA2_STARTUP_LOG"
|
||||
echo "Icinga 2 detected configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
|
||||
exit 1
|
||||
else
|
||||
echo "Not "$1"ing Icinga 2 due to configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
|
||||
echo "Not ${1}ing Icinga 2 due to configuration errors. Check '$ICINGA2_STARTUP_LOG' for details."
|
||||
if [ "x$2" = "xfail" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
@ -128,7 +139,7 @@ checkconfig() {
|
|||
echo "Done"
|
||||
# no arguments requires full output
|
||||
if [ "x$1" = "x" ]; then
|
||||
cat $ICINGA2_STARTUP_LOG
|
||||
cat "$ICINGA2_STARTUP_LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -136,13 +147,13 @@ checkconfig() {
|
|||
status() {
|
||||
printf "Icinga 2 status: "
|
||||
|
||||
if [ ! -e $ICINGA2_PID_FILE ]; then
|
||||
if [ ! -e "$ICINGA2_PID_FILE" ]; then
|
||||
echo "Not running"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
pid=`cat $ICINGA2_PID_FILE`
|
||||
if icinga2 internal signal -s SIGCHLD -p $pid >/dev/null 2>&1; then
|
||||
pid=`cat "$ICINGA2_PID_FILE"`
|
||||
if icinga2 internal signal -s SIGCHLD -p "$pid" >/dev/null 2>&1; then
|
||||
echo "Running"
|
||||
else
|
||||
echo "Not running"
|
||||
|
@ -152,37 +163,36 @@ status() {
|
|||
|
||||
### main logic ###
|
||||
case "$1" in
|
||||
start)
|
||||
checkconfig start fail
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
start)
|
||||
checkconfig start fail
|
||||
start
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
restart)
|
||||
checkconfig restart fail
|
||||
stop nofail
|
||||
start
|
||||
;;
|
||||
condrestart)
|
||||
STATUS=$(status > /dev/null 2>&1)
|
||||
if [ $? != 0 ]; then exit 0; fi
|
||||
checkconfig restart fail
|
||||
stop nofail
|
||||
start
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
checkconfig)
|
||||
checkconfig
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|reload|checkconfig|status}"
|
||||
exit 3
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
status)
|
||||
status
|
||||
;;
|
||||
restart)
|
||||
checkconfig restart fail
|
||||
stop nofail
|
||||
start
|
||||
;;
|
||||
condrestart)
|
||||
status > /dev/null 2>&1 || exit 0
|
||||
checkconfig restart fail
|
||||
stop nofail
|
||||
start
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
checkconfig)
|
||||
checkconfig
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|reload|checkconfig|status}"
|
||||
exit 3
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
|
|
@ -14,28 +14,39 @@ fi
|
|||
|
||||
# Set defaults, to overwrite see "@ICINGA2_SYSCONFIGFILE@"
|
||||
|
||||
: ${ICINGA2_USER:="@ICINGA2_USER@"}
|
||||
: ${ICINGA2_GROUP:="@ICINGA2_GROUP@"}
|
||||
: ${ICINGA2_COMMAND_GROUP:="@ICINGA2_COMMAND_GROUP@"}
|
||||
: ${ICINGA2_INIT_RUN_DIR:="@ICINGA2_FULL_INITRUNDIR@"}
|
||||
: ${ICINGA2_LOG_DIR:="@ICINGA2_FULL_LOGDIR@"}
|
||||
: ${ICINGA2_CACHE_DIR:="@ICINGA2_FULL_CACHEDIR@"}
|
||||
: "${ICINGA2_USER:="@ICINGA2_USER@"}"
|
||||
: "${ICINGA2_GROUP:="@ICINGA2_GROUP@"}"
|
||||
: "${ICINGA2_COMMAND_GROUP:="@ICINGA2_COMMAND_GROUP@"}"
|
||||
: "${ICINGA2_INIT_RUN_DIR:="@ICINGA2_FULL_INITRUNDIR@"}"
|
||||
: "${ICINGA2_LOG_DIR:="@ICINGA2_FULL_LOGDIR@"}"
|
||||
: "${ICINGA2_CACHE_DIR:="@ICINGA2_FULL_CACHEDIR@"}"
|
||||
|
||||
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)
|
||||
if ! getent passwd "$ICINGA2_USER" >/dev/null 2>&1; then
|
||||
echo "Icinga user '$ICINGA2_USER' does not exist. Exiting."
|
||||
exit 6
|
||||
fi
|
||||
|
||||
if ! getent group "$ICINGA2_GROUP" >/dev/null 2>&1; then
|
||||
echo "Icinga group '$ICINGA2_GROUP' does not exist. Exiting."
|
||||
exit 6
|
||||
fi
|
||||
|
||||
if ! getent group "$ICINGA2_COMMAND_GROUP" >/dev/null 2>&1; then
|
||||
echo "Icinga command group '$ICINGA2_COMMAND_GROUP' does not exist. Exiting."
|
||||
exit 6
|
||||
fi
|
||||
|
||||
if [ ! -e "$ICINGA2_INIT_RUN_DIR" ]; then
|
||||
mkdir -m 755 "$ICINGA2_INIT_RUN_DIR"
|
||||
mkdir -m 2750 "$ICINGA2_INIT_RUN_DIR"/cmd
|
||||
fi
|
||||
|
||||
chown -R $ICINGA2_USER:$ICINGA2_COMMAND_GROUP "$ICINGA2_INIT_RUN_DIR"
|
||||
chown -R "$ICINGA2_USER:$ICINGA2_COMMAND_GROUP" "$ICINGA2_INIT_RUN_DIR"
|
||||
|
||||
test -e "$ICINGA2_LOG_DIR" || install -m 750 -o $ICINGA2_USER -g $ICINGA2_COMMAND_GROUP -d "$ICINGA2_LOG_DIR"
|
||||
test -e "$ICINGA2_LOG_DIR" || install -m 750 -o "$ICINGA2_USER" -g "$ICINGA2_COMMAND_GROUP" -d "$ICINGA2_LOG_DIR"
|
||||
|
||||
if type restorecon >/dev/null 2>&1; then
|
||||
restorecon -R "$ICINGA2_INIT_RUN_DIR"/
|
||||
fi
|
||||
|
||||
test -e "$ICINGA2_CACHE_DIR" || install -m 750 -o $ICINGA2_USER -g $ICINGA2_COMMAND_GROUP -d "$ICINGA2_CACHE_DIR"
|
||||
test -e "$ICINGA2_CACHE_DIR" || install -m 750 -o "$ICINGA2_USER" -g "$ICINGA2_COMMAND_GROUP" -d "$ICINGA2_CACHE_DIR"
|
||||
|
|
|
@ -5,14 +5,15 @@ if [ "$1" != "" ]; then
|
|||
if [ -r "$1" ]; then
|
||||
. "$1"
|
||||
else
|
||||
echo "Unable to read sysconf from '$1'. Exiting." && exit 6
|
||||
echo "Unable to read sysconf from '$1'. Exiting."
|
||||
exit 6
|
||||
fi
|
||||
fi
|
||||
|
||||
# Set defaults, to overwrite see "@ICINGA2_SYSCONFIGFILE@"
|
||||
|
||||
: ${ICINGA2_PID_FILE:="@ICINGA2_FULL_INITRUNDIR@/icinga2.pid"}
|
||||
: ${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"}
|
||||
: "${ICINGA2_PID_FILE:="@ICINGA2_FULL_INITRUNDIR@/icinga2.pid"}"
|
||||
: "${DAEMON:="@CMAKE_INSTALL_FULL_SBINDIR@/icinga2"}"
|
||||
|
||||
printf "Validating config files: "
|
||||
|
||||
|
@ -20,29 +21,29 @@ OUTPUTFILE=`mktemp`
|
|||
|
||||
if type selinuxenabled >/dev/null 2>&1; then
|
||||
if selinuxenabled; then
|
||||
chcon -t icinga2_tmp_t $OUTPUTFILE >/dev/null 2>&1
|
||||
chcon -t icinga2_tmp_t "$OUTPUTFILE" >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! $DAEMON daemon --validate --color > $OUTPUTFILE; then
|
||||
if ! "$DAEMON" daemon --validate --color > "$OUTPUTFILE"; then
|
||||
echo "Failed"
|
||||
|
||||
cat $OUTPUTFILE
|
||||
rm -f $OUTPUTFILE
|
||||
cat "$OUTPUTFILE"
|
||||
rm -f "$OUTPUTFILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Done"
|
||||
rm -f $OUTPUTFILE
|
||||
rm -f "$OUTPUTFILE"
|
||||
|
||||
printf "Reloading Icinga 2: "
|
||||
|
||||
if [ ! -e $ICINGA2_PID_FILE ]; then
|
||||
if [ ! -e "$ICINGA2_PID_FILE" ]; then
|
||||
exit 7
|
||||
fi
|
||||
|
||||
pid=`cat $ICINGA2_PID_FILE`
|
||||
if ! kill -HUP $pid >/dev/null 2>&1; then
|
||||
pid=`cat "$ICINGA2_PID_FILE"`
|
||||
if ! kill -HUP "$pid" >/dev/null 2>&1; then
|
||||
echo "Error: Icinga not running"
|
||||
exit 7
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue