cups/cups.startup

201 lines
5.8 KiB
Text
Raw Normal View History

2012-02-01 14:24:38 +04:00
#!/bin/bash
# Init file for the CUPS server daemon
#
# chkconfig: 2345 15 60
# description: The Common UNIX Printing System (CUPS), an \
# advanced printer spooling system which \
# allows setting of printer options and \
# automatic availability of a printer \
# configured on one server in the whole \
# network. Default printing system of Mandriva \
# Linux.
#
# processname: cupsd
# config: /etc/cups/cupsd.conf
# config: /etc/cups/client.conf
# config: /etc/cups/classes.conf
# config: /etc/cups/printers.conf
# config: /etc/cups/mime.types
# config: /etc/cups/mime.convs
# config: /etc/cups/ppds.dat
#
### BEGIN INIT INFO
# Provides: cups
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Short-Description: CUPS printing server daemon
# Description: The Common UNIX Printing System (CUPS), an
# advanced printer spooling system which
# allows setting of printer options and
# automatic availability of a printer
# configured on one server in the whole
# network. Default printing system of Mandriva
# Linux.
### END INIT INFO
# source function library
. /etc/rc.d/init.d/functions
# default printing auto admin settings
ENABLE_QUEUES_ON_SPOOLER_START=no
# source printing auto admin configuration
if [ -r /etc/sysconfig/printing ]; then
. /etc/sysconfig/printing
fi
# Source an auxiliary options file if we have one, and pick up OPTIONS
# CUPS can now play nice (use NICELEVEL=<number> in /etc/sysconfig/cups)
if [ -r /etc/sysconfig/cups ] ; then
. /etc/sysconfig/cups
fi
# Don't use TMPDIR environment variable from init script, as that can
# cause cupsd to set TempDir to a user's temporary directory instead
# of the default...
#
unset TMPDIR
RETVAL=0
case "$1" in
start)
# Turn off the CUPS-LPD mini-daemon when LPD is running
if [ -x /etc/rc.d/init.d/lpd ]; then
if (export LC_ALL=C; /sbin/service lpd status | /bin/egrep "running" > /dev/null 2>&1); then
if (export LC_ALL=C; /sbin/chkconfig --list cups-lpd | /bin/egrep "on$" > /dev/null 2>&1); then
echo "Turning off CUPS-LPD mini daemon ..."
/sbin/chkconfig --del cups-lpd
if [ -x /usr/sbin/xinetd ]; then
/sbin/service xinetd condrestart
fi
fi
fi
fi
# Check whether a parallel printer is configured and if
# so, but if the parallel printer kernel module not being
# loaded, load the module.
if (/bin/egrep "^[^#]*/dev/lp" /etc/cups/printers.conf > /dev/null 2>&1); then
if (! (export LC_ALL=C; /sbin/lsmod | /bin/egrep "^lp +" > /dev/null 2>&1) || \
! (export LC_ALL=C; /sbin/lsmod | /bin/egrep "^parport_pc +" > /dev/null 2>&1)); then
echo "Loading parallel port printer kernel modules ..."
modprobe parport_pc > /dev/null 2>&1;
RET=$?
if [ $RET -eq 0 ]; then
modprobe lp > /dev/null 2>&1;
RET=$?
fi
if [ $RET -ne 0 ]; then
echo
echo "WARNING: Parallel printer kernel modules could not be loaded, your parallel"
echo " printer may not work."
echo
fi
fi
fi
# Check whether an OKI winprinter is configured with and if so,
# but if the oki4daemon not being running, start the oki4daemon.
if (/bin/egrep "^[^#]*/dev/oki4drv" /etc/cups/printers.conf > /dev/null 2>&1); then
if ! (/bin/ps auxwww | /bin/grep -v "grep" | /bin/grep "oki4daemon" > /dev/null 2>&1); then
echo "Starting oki4daemon ..."
chkconfig --add oki4daemon
/sbin/service oki4daemon start
fi
fi
# Do automatic correction of CUPS configuration to avoid
# /etc/printcap from LPD/LPRng being overwritten and also
# to avoid printer info with hostname "localhost" being
# broadcasted. Can be turned off in printerdrake
if [ -x /usr/sbin/correctcupsconfig ]; then
/usr/sbin/correctcupsconfig
fi
echo -n "Starting CUPS printing system: "
portrelease cups
daemon cupsd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/cups
# CUPS daemon must be listening for the following steps
if (ps auxwww | grep cupsd | grep -v grep > /dev/null 2>&1); then
if ! (lpstat -r > /dev/null 2>&1); then
echo -en "Waiting for the CUPS daemon getting ready"
for ((i=0; i < 30; i ++)); do
if (lpstat -r > /dev/null 2>&1); then
break;
fi;
sleep 1;
echo -en ".";
done;
echo ""
fi
if ! (lpstat -r > /dev/null 2>&1); then
echo "WARNING: CUPS daemon still not listening after 30 sec, aborting auto-admin tasks."
exit $RETVAL
fi;
fi
if [ "$ENABLE_QUEUES_ON_SPOOLER_START" == "yes" ]; then
# Re-enable disabled print queues
gprintf "Re-enabling disabled print queues:\n"
for printer in `lpstat -p | grep disabled | cut -d ' ' -f 2`; do
if cat /etc/cups/printers.conf | egrep -q "<(Default|)Printer $printer>"; then
#if (( ! `lpstat -p $printer | grep -c Paused` )); then
gprintf " Printer: $printer\n";
/usr/bin/enable $printer
#fi
fi
done
fi
if [ $RETVAL = 0 ]; then
echo_success
echo
else
echo_failure
echo
fi
;;
stop)
echo -n "Stopping CUPS printing system: "
killproc cupsd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/cups
;;
restart)
$0 stop
$0 start
RETVAL=$?
;;
status)
status cupsd
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/cups ]; then
$0 stop
$0 start
RETVAL=$?
fi
;;
reload)
echo -n "Reinitializing CUPS printing system: "
killproc cupsd -HUP
RETVAL=$?
echo
;;
*)
echo "Usage: cups {start|stop|restart|reload|status|condrestart}"
exit 1
esac
exit $RETVAL