File ido2db-exec-start-pre of Package icinga.3888

#! /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/ido2db.cfg" | sed 's@=@ @' | tr -d '[:cntrl:]'`
    fi
    shift # remove first ARG => search-string
    echo $*
}

# get variables from config file
ido2db_user="$(get_var ido2db_user)"
ido2db_group="$(get_var ido2db_group)"
lock_file="$(get_var lock_file)"
socket_name="$(get_var socket_name)"

# use default values if above check doesn't work
: ${ido2db_user:=icinga}
: ${ido2db_group:=icinga}
: ${lock_file:=/var/run/icinga/ido2db.pid}
: ${socket_name:=/var/run/icinga/ido2db.sock}

# remove some perhaps left over files
for file in "$lock_file" "$socket_name"; do
    test -e "$file" && rm -f "$file"
done

# make sure that all necessary directories are there
install -d -m755 -o$ido2db_user -g$ido2db_group $(dirname "$lock_file")
openSUSE Build Service is sponsored by