#!/bin/sh
#
# p910nd	This shell script takes care of starting and stopping
#               p910nd (port 9100+n printer daemon).
#               This script only controls the one on port 9101.
#               You can start others if you wish.
# chkconfig: 2345 90 25
# description: p910nd is a small printer daemon intended for diskless
#              workstations that does not spool to disk but passes the
#              job directly to the printer.
# processname: p910nd
# config: /etc/printcap
# pidfile: /var/run/p910nd.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/p910nd.pid
LOCKFILE=/var/lock/subsys/p910nd
RETVAL=0

start()
{
	SourceIfNotEmpty /etc/sysconfig/p910nd
	is_yes ${BIDIRECT:-0} && BIDIRECT=" -b" || BIDIRECT=""
	if [ -n "$PORT" ]; then
	    if [ $PORT -gt 2 ]; then
		[ $PORT -ge 9100 -a $PORT -le 9102 ] && PORT=${PORT:3} || PORT=""
	    fi
	fi
	start_daemon --make-pidfile --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- \
	    p910nd $OPTIONS${DEVICE:+ -f $DEVICE}${BINDADDR:+ -i $BINDADDR}$BIDIRECT${PORT:+ $PORT}
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- p910nd
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- p910nd
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
