#!/bin/sh

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/lpd
PIDFILE=/var/spool/lpd/lpd.lock

test -x $DAEMON -a -f /usr/sbin/pac || exit 0

case "$1" in
  start)
	echo -n "Starting printer spooler: lpd"
        if start-stop-daemon --quiet --stop --signal 0 --pidfile $PIDFILE --name lpd
	then
		echo " already running."
		exit
	fi
	/sbin/start-stop-daemon --start --quiet --exec $DAEMON
	echo "."
	;;
  stop)
	echo -n "Stopping printer spooler: lpd"
	if start-stop-daemon --quiet --stop --signal 0 --pidfile $PIDFILE --name lpd
	then
		PID=`cat $PIDFILE`
		start-stop-daemon --quiet --stop --exec $DAEMON --pidfile $PIDFILE --name lpd
		# Now we wait for it to die
		while kill -0 $PID 2>/dev/null; do sleep 1; done
		echo "."
	else
		echo " not running.";
	fi
	;;
  force-reload|restart)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: /etc/init.d/lpd {start|stop|restart|force-reload}"
	exit 1
esac

exit 0
