#! /bin/sh
# Copyright (c) 1995-1998 SuSE GmbH Nuernberg, Germany.
#
# Author: adrian@suse.de, template by ro@suse.de
#
# /etc/init.d/distccd
#   and its symbolic  link
# /usr/sbin/rcdistccd
#
### BEGIN INIT INFO
# Provides:          distccd
# Required-Start:    
# Required-Stop:
# Default-Start:     3 5
# Default-Stop:
# Description:       distributed compiler daemon
### END INIT INFO

# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}

# Force execution if not called by a runlevel directory.
test -x /usr/sbin/distccd || exit 0

. /etc/rc.status
. /etc/sysconfig/distccd

# does not work as nobody
# PIDFILE=/var/run/distccd.pid

rc_reset
case "$1" in
    start)
	echo -n "Starting Distributed Compiler Daemon"
	[ "${DISTCCD_LOG_FILE:0:1}" == "/" ] && \
	  LOG="--log-file=$DISTCCD_LOG_FILE"
	startproc -q -u nobody -g nogroup \
		/usr/sbin/distccd --daemon \
				  -N $DISTCCD_NICE_LEVEL \
				  -p $DISTCCD_PORT \
				  $LOG
	rc_status -v
	;;
    stop)
	echo -n "Shutting down Distributed Compiler Daemon"
	killproc -TERM /usr/sbin/distccd
	rc_status -v
	;;
    restart)
	## If first returns OK call the second, if first or
	## second command fails, set echo return value.
	$0 stop; sleep 1  &&  $0 start
	rc_status
	;;
    reload|force-reload)
	$0 stop  &&  $0 start
	rc_status
	;;
    status)
	echo -n "Checking for Distributed Compiler Daemon: "
	checkproc /usr/sbin/distccd
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|reload}"
	exit 1
	;;
esac
rc_exit
