#!/bin/sh

CFWORKDIR=__CFWORKDIR

case "$1" in
start)
	[ -x $CFWORKDIR/bin/cfservd ] && $CFWORKDIR/bin/cfservd
	[ -x $CFWORKDIR/bin/cfenvd ] && $CFWORKDIR/bin/cfenvd -H
	[ -x $CFWORKDIR/bin/cfexecd ] && $CFWORKDIR/bin/cfexecd
	([ -x $CFWORKDIR/bin/cfservd ] && [ -x $CFWORKDIR/bin/cfenvd ] && \
	 [ -x $CFWORKDIR/bin/cfexecd ] && [ -x $CFWORKDIR/bin/cfagent ]) \
		|| __PREFIX/sbin/cfagent --no-splay -f update.conf
	;;
stop)
	/usr/bin/killall -SIGUSR1 cfagent 2>/dev/null
	/usr/bin/killall -SIGUSR1 cfexecd 2>/dev/null
	/usr/bin/killall -SIGUSR1 cfenvd 2>/dev/null
	/usr/bin/killall -SIGUSR1 cfservd 2>/dev/null
	;;
restart)
	$0 stop
	$0 start
	;;
*)
	echo "Usage: `basename $0` {start|stop|restart}" >&2
	;;
esac

exit 0

