#!/bin/sh
#
# Startup script for distccd
#
### BEGIN INIT INFO
# Provides: distccd
# Required-Start: $network
# Required-Stop: $network 
# Description: distccd is a program to distribute compilation of C or C++ code
#across several machines on a network.
# Short-Description: start and stop distccd
# Default-Start: 3 4 5 
# Default-Stop: O 1 2 6
### END INIT INFO
# chkconfig: 345 85 15
# description: distccd is a program to distribute compilation of C or C++ code \
#              across several machines on a network. distcc should always \
#              generate the same results as a local compile, is simple to \
#              install and use, and is often two or more times faster than \
#              a local compile.
#               
# processname: distccd
# config: /etc/sysconfig/distcc

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network
. /etc/sysconfig/distcc

# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
	exit 0
fi

[ -x /usr/bin/distccd ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
  start)
	gprintf "Starting distccd: "
        touch /var/run/distccd.pid
        chown distccd:distccd /var/run/distccd.pid
        daemon --user distccd distccd --daemon --pid-file=/var/run/distccd.pid --log-file=$DISTCC_LOG --allow=$IP_ALLOW
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/distccd
	;;
  stop)
	gprintf "Shutting down distccd: "
	killproc distccd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/distccd
	;;
  status)
	status distccd
	RETVAL=$?
	;;
  restart)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  reload)
	gprintf "Re-reading distccd config: "
	killproc distccd -HUP
	RETVAL=$?
	echo
	;;
  *)
	gprintf "Usage: %s {start|stop|status|restart|reload}\n" "$0"
	exit 1
esac

if [ $# -gt 1 ]; then
	shift
	$0 $*
fi

exit $RETVAL
