#!/sbin/sh
#
# @(#) $Revision: 72.8 $
#
# NOTE:    This script is not configurable!  Any changes made to this
#          scipt will be overwritten when you upgrade to the next
#          release of HP-UX.
#
# WARNING: Changing this script in any way may lead to a system that
#          is unbootable.  Do not modify this script.
#

#
# Start lp printer scheduler, if configured.
#
# NOTE:
# For RS-232 printers:
#     If your line printer interface is RS232 and not set
#     to 300 baud, then change the 'lp' line in
#     /etc/inittab from 'off' to 'once' and make sure the
#     baud rate set there is correct for your printer.
#
#

PATH=/usr/sbin:/usr/bin:/sbin
export PATH

rval=0
set_return() {
	x=$?
	if [ $x -ne 0 ]; then
		echo "EXIT CODE: $x"
		rval=1
	fi
}

case $1 in
start_msg)
	echo "Start print spooler"
	;;

stop_msg)
	echo "Stop print spooler"
	;;

'start')
	if [ -f /etc/rc.config.d/lp ] ; then
		. /etc/rc.config.d/lp
	else
		echo "ERROR: /etc/rc.config.d/lp defaults file MISSING"
	fi
	
	if [ "$LP" -eq 1 -a -s /var/spool/lp/pstatus ]; then
                ps -ef | grep lpsched | grep -iv grep > /dev/null 2>&1
                if [ $? = 0 ]
                then
		   /usr/sbin/lpshut > /dev/null 2>&1
		set_return
                fi
		rm -f /var/spool/lp/SCHEDLOCK
		/usr/sbin/lpsched && echo line printer scheduler started
		set_return
	else
		rval=2
	fi
	;;

'stop')
	if [ -s /var/spool/lp/pstatus ]; then
		if /usr/sbin/lpshut > /dev/null 2>&1; then
			echo line printer scheduler stopped
		else
			set_return
		fi
	fi
	;;

*)
	echo "usage: $0 {start|stop}"
	;;
esac

exit $rval
