#!/sbin/openrc-run
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

: ${CFGFILE:=/etc/nagios/nsca.cfg}

get_config() {
    [ -f ${CFGFILE} ] || return 1

    sed -n -e 's:^[ \t]*'$1'=\([^#]\+\).*:\1:p' \
	${CFGFILE}
}

extra_started_commands="reload"

command=/usr/libexec/${SVCNAME}
command_args="-c ${CFGFILE} --daemon"
pidfile=$(get_config pid_file)

depend() {
    config ${CFGFILE}

    case $(get_config nsca_user) in
	icinga) need icinga ;;
	nagios) need nagios ;;
    esac
}

reload() {
    ebegin "Reloading ${SVCNAME}"
    kill -HUP `cat $(get_config pid_file)`
    eend $?
}
