File icinga-exec-start-pre of Package icinga.9111
#! /bin/sh
# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany
#
# Author: Tim Hardeck
# bases on the SUSE Icinga init script from Wolfgang Rosenauer, Lars Vogdt
#
# grab a config option
get_var() {
if [ -n "$2" ]; then
set -- `grep ^$1 $2 | sed 's@=@ @' | tr -d '[:cntrl:]'`
else
set -- `grep ^$1 "/etc/icinga/icinga.cfg" | sed 's@=@ @' | tr -d '[:cntrl:]'`
fi
shift # remove first ARG => search-string
echo $*
}
# get variables from config file
icinga_user="$(get_var icinga_user)"
icinga_group="$(get_var icinga_group)"
temp_path="$(get_var temp_path)"
command_file="$(get_var command_file)"
lock_file="$(get_var lock_file)"
status_file="$(get_var status_file)"
temp_file="$(get_var temp_file)"
# use default values if above check doesn't work
: ${icinga_user:=icinga}
: ${icinga_group:=icinga}
: ${icinga_cmdgrp:=icingacmd}
: ${temp_path:=/var/run/icinga/tmp}
: ${command_file:=/var/run/icinga/icinga.cmd}
: ${lock_file:=/var/run/icinga/icinga.pid}
: ${status_file:=/var/spool/icinga/status.dat}
: ${temp_file:=/var/run/icinga/icinga.tmp}
# remove some perhaps left over files
for file in "$command_file" "$lock_file" "$status_file" "$temp_file"; do
test -f "$file" && rm -f "$file"
done
# make sure that all necessary directories are there
install -d -m755 -o$icinga_user -g$icinga_group $(dirname "$lock_file")
install -d -m775 -o$icinga_user -g$icinga_group $(dirname "$temp_file")
if [ ! -d "$temp_path" ]; then
case "$temp_path" in
/var/run/icinga/tmp)
install -d -m775 -o$icinga_user -g$icinga_group "$temp_path"
;;
*)
/bin/logger -t rcicinga "$temp_path does not exist - creating now"
install -d -m775 -o$icinga_user -g$icinga_group "$temp_path"
;;
esac
fi
# create command file with correct permissions
mkfifo -m 660 "$command_file"
chown --no-dereference $icinga_user:$icinga_cmdgrp "$command_file"