#!/bin/sh
#
# $Id$
#
# distccd		distccd
#
# chkconfig:	345 55 45
#
# description:	distccd
#

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

# Get network config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/distccd ] && . /etc/sysconfig/distccd

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down distccd
		exit 1
	fi
else
	exit 0
fi

[ -z "$DISTCC_HOSTS_ALLOW" -a -n "$HOSTS_ALLOW" ] && DISTCC_HOSTS_ALLOW="$HOSTS_ALLOW"

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/distccd ]; then
		msg_starting distccd
		touch distcc /var/log/distcc
		chown distcc /var/log/distcc
		daemon /usr/bin/distccd --daemon --user distcc --log-file /var/log/distcc `for ip in $DISTCC_HOSTS_ALLOW; do echo -n "--allow $ip "; done` $DISTCC_OPTS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/distccd
	else
		msg_already_running distccd
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/distccd ]; then
		msg_stopping distccd
		killproc distccd
		rm -f /var/run/distccd.pid /var/lock/subsys/distccd >/dev/null 2>&1
	else
		msg_not_running distccd
	fi
	;;
  restart)
	$0 stop
	$0 start
	exit $?
	;;
  status)
	status distccd
	exit $?
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/distccd ]; then
		msg_reloading distccd
		killproc distccd -HUP
		RETVAL=$?
	else
		msg_not_running distccd >&2
		exit 7
	fi
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL

# This must be last line !
# vi:syntax=sh:tw=78:ts=4:sw=4
