#! /bin/sh
#
# chkconfig: 345 80 15
# description: The distcc deamon
#              http://distcc.samba.org
#
# processname: distccd

# Written by Pavel Mironchik <tibor@altlinux.ru>
# Patched for proper ACL list by LAKostis <lakostis@altlinux.ru>

. /etc/init.d/functions

OPTIONS=""
RUNUSER="distccd"
PORT=3632
ALLOW="127.0.0.1/24"
SourceIfNotEmpty /etc/sysconfig/distccd

RETVAL=0
SERVICE=distccd
LOCKFILE=/var/lock/subsys/distccd
PIDFILE=/var/run/distccd.pid


start() {

	ACL=
	for serv in $ALLOW
	do
	  ACL="$ACL --allow $serv"
	done

	[ -z "$LISTEN" ] || OPTIONS="$OPTIONS --listen $LISTEN"

	start_daemon  --pidfile "$PIDFILE" --lockfile "$LOCKFILE" -- \
		/usr/bin/distccd --daemon --user $RUNUSER \
		$ACL $OPTIONS
	
	RETVAL=$?
	return $RETVAL
}	


stop() {
	eval "msg_stopping distccd"
	eval "killproc distccd"
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f $LOCKFILE && rm -f $PIDFILE
	return $RETVAL
}


restart()
{
	stop
	start
}


case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart|reload)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status  distccd
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac
exit $RETVAL
