print/cups/cupsd

Fri, 15 Nov 2019 20:11:00 +0100

author
David Demelier <markand@malikania.fr>
date
Fri, 15 Nov 2019 20:11:00 +0100
changeset 1210
422313c3fcbd
parent 1147
ef803d8555ec
permissions
-rw-r--r--

text/rarian: initial import, closes #2311

#!/bin/busybox sh
#
# /etc/rc.d/cupsd -- run control script for cupsd
#
# Copyright (c) 2019 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

if [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi

: ${CUPSD_CMD:=/bin/cupsd}
: ${CUPSD_ARGS:=}
: ${CUPSD_PID:=/var/run/cups/cupsd.pid}

cupsd_start()
{
	mkdir -p $(dirname $CUPSD_PID)

	if [ -s $CUPSD_PID ]; then
		echo "cupsd is already running with pid: $(cat $CUPSD_PID)"
	else
		echo "Starting cupsd: $CUPSD_CMD $CUPSD_ARGS"
		$CUPSD_CMD $CUPSD_ARGS
	fi
}

cupsd_status()
{
	if [ -s $CUPSD_PID ]; then
		echo "cupsd is running with pid: $(cat $CUPSD_PID)"
	else
		echo "cupsd is not running"
	fi
}

cupsd_stop()
{
	if [ -s $CUPSD_PID ]; then
		echo "Stopping cupsd."
		kill -QUIT $(cat $CUPSD_PID)
	fi
}

cupsd_restart()
{
	cupsd_stop
	sleep 3
	cupsd_start
}

case $1 in
start)
	cupsd_start
	;;
status)
	cupsd_status
	;;
stop)
	cupsd_stop
	;;
restart)
	cupsd_restart
	;;
*)
	echo "usage: $(basename $0) restart|start|status|stop"
	;;
esac

mercurial