#!/bin/sh
#
# LPRng		This shell script takes care of starting and stopping
#		LPRng lpd (printer daemon).
#
# chkconfig:	2345 60 60
#
# description:	LPRng lpd is the print daemon required for lpr to work properly. \
#		It is basically a server that arbitrates print jobs to printer(s).
#
# processname:	lpd
# config:	/etc/printcap


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

# Get network config
. /etc/sysconfig/network

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

# 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 LPRng
		exit 1
	fi
else
	exit 0
fi

# Sanity check
[ -f /etc/printcap ] || exit 0

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/lpd ]; then
		msg_starting LPRng
		daemon lpd
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/lpd
	else
		msg_already_running "LPRng"
	fi
}

stop() {
	if [ -f /var/lock/subsys/lpd ]; then
		msg_stopping "LPRng"
		killproc lpd
		rm -f /var/lock/subsys/lpd >/dev/null 2>&1
	else
		msg_not_running "LPRng"
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/lpd ]; then
		stop
		start
	else
		msg_not_running "LPRng"
		RETVAL=$1
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status lpd
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
