#!/sbin/runscript
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

OPSIPXECONFDCONFIG=/etc/opsi/opsipxeconfd.conf
OPSIPXECONFDPROGRAM=/usr/bin/opsipxeconfd

[ -x $OPSIPXECONFDPROGRAM ] || exit 0

OPSIPXECONFDCONFIG_OPT=""
[ ! -z $OPSIPXECONFDCONFIG -a -f $OPSIPXECONFDCONFIG ] && OPSIPXECONFDCONFIG_OPT="-c $OPSIPXECONFDCONFIG"

USER=root
LOGDIR=/var/log/opsi/opsipxeconfd
PIDDIR=/var/run/opsipxeconfd
LIBDIR=/var/lib/opsipxeconfd
PIDFILE=${PIDDIR}/opsipxeconfd.pid



depend() {
	need opsiconfd
}

start() {
	# Make sure files are writable
	[ ! -e  ${LOGDIR} ] && mkdir -p ${LOGDIR}
	chown -R ${USER} ${LOGDIR}
	[ ! -e  ${LIBDIR} ] && mkdir -p ${LIBDIR}
	chown -R ${USER} ${LIBDIR}
	[ ! -e  ${PIDDIR} ] && mkdir -p ${PIDDIR}
	chown -R ${USER} ${PIDDIR}

	ebegin "Starting opsi pxe config service"
	start-stop-daemon --start \
		--user ${USER} \
		--pidfile ${PIDFILE} \
		--exec ${OPSIPXECONFDPROGRAM} -- -D ${OPSIPXECONFDCONFIG_OPT} ${OPSIPXECONFD_OPTIONS}
	eend $?
}

stop() {
	ebegin "Stopping opsi pxe config service"
	start-stop-daemon --stop \
		--pidfile ${PIDFILE} \
		--exec ${OPSIPXECONFDPROGRAM} -- ${OPSIPXECONFDCONFIG_OPT}
	eend $?
}