summaryrefslogtreecommitdiff
path: root/print/cups/files/cupsd.sh
blob: 4000f876f33377fcfac64aad09cc2690c54edbaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!@RCD_SCRIPTS_SHELL@
#
# $NetBSD: cupsd.sh,v 1.19 2005/01/06 07:26:39 jlam Exp $
#
# Common UNIX Printing System daemon
#
# PROVIDE: cupsd
# REQUIRE: DAEMON slpd
#
# You will need to set some variables in /etc/rc.conf to start cupsd:
#
# cupsd=YES
# cupsd_wait=YES	# set to "YES" to wait for cupsd to detect printers;
#			#   this variable is optional and defaults to "NO".
# cupsd_timeout=60	# set to the number of seconds we wait for cupsd
#			#   to respond before we declare it not responding;
#			#   this variable is optional and defaults to "60".

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

name="cupsd"
rcvar=${name}
command="@PREFIX@/sbin/${name}"
lpstat_command="@PREFIX@/bin/lpstat"
command_args="& sleep 2"
required_files="@PKG_SYSCONFDIR@/${name}.conf"
extra_commands="reload wait"
wait_cmd="cupsd_waitcmd"
start_postcmd="cupsd_poststart"

cupsd_poststart()
{
	if checkyesno cupsd_wait; then
		run_rc_command wait
	fi
}

cupsd_waitcmd()
{
	if [ -x ${lpstat_command} ]; then
		msg=
		@ECHO@ -n "Waiting ${cupsd_timeout} seconds for ${name}: "
		if ${lpstat_command} -r >/dev/null 2>&1; then
			msg='responding'
		else
			master=$$
			trap "msg='not responding'" ALRM
			(sleep ${cupsd_timeout} && kill -ALRM $master) >/dev/null 2>&1 &
			while [ -z "$msg" ]; do
				if ${lpstat_command} -r >/dev/null 2>&1; then
					msg='responding'
					trap : ALRM
				else
					sleep 5
					@ECHO@ -n '.'
				fi
			done
		fi
		@ECHO@ "$msg"
	fi
}

if [ -f /etc/rc.subr ]; then
	load_rc_config $name
	: ${cupsd_wait:=NO}
	: ${cupsd_timeout:=60}
	run_rc_command "$1"
else
	@ECHO@ -n " ${name}"
	${command} ${cupsd_flags} ${command_args}
fi