#!/sbin/openrc-run

NAME="nutcracker"
DAEMON=/usr/sbin/nutcracker
USER="${USER:-nobody}"
CONFFILE="${CONFFILE:-/etc/nutcracker/nutcracker.yml}"

DAEMON_ARGS=${DAEMON_ARGS:-"-c $CONFFILE -o $LOGFILE -p $PIDFILE -d"}

depend() {
	need net
	after firewall
}

checkconf() {
	ebegin "Testing configuration: "
		${DAEMON} --test-conf \
		--conf-file=${CONFFILE} \
		>/dev/null 2>&1
	eend $?
}


start() {
	checkconf || exit 1
	ebegin "Starting ${NAME}: "
		start-stop-daemon --start --quiet \
			--pidfile ${PIDFILE} \
			--chuid ${USER}:${USER} \
			--exec ${DAEMON} -- ${DAEMON_ARGS}
	eend $?
}

stop() {
	ebegin "Stopping ${NAME}: "
		start-stop-daemon --stop --quiet \
			--pidfile ${PIDFILE} \
			--exec ${DAEMON}
	eend $?
}


