• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Startup/shutdown script for CUPS.
4#
5# Copyright © 2007-2013 by Apple Inc.
6# Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7#
8# Licensed under Apache License v2.0.  See the file "LICENSE" for more
9# information.
10#
11
12#### OS-Dependent Information
13
14#
15#   Linux chkconfig stuff:
16#
17#   chkconfig: 235 99 00
18#   description: Startup/shutdown script for CUPS.
19#
20
21#
22#   NetBSD 1.5+ rcorder script lines.  The format of the following two
23#   lines is very strict -- please don't add additional spaces!
24#
25# PROVIDE: cups
26# REQUIRE: DAEMON
27#
28
29
30#### OS-Dependent Configuration
31
32case "`uname`" in
33	*BSD*)
34        	IS_ON=:
35		ECHO=echo
36		ECHO_OK=:
37		ECHO_ERROR=:
38		;;
39
40	Darwin*)
41		. /etc/rc.common
42
43		if test "${CUPS:=-YES-}" = "-NO-"; then
44			exit 0
45		fi
46
47        	IS_ON=:
48		ECHO=ConsoleMessage
49		ECHO_OK=:
50		ECHO_ERROR=:
51		;;
52
53	Linux*)
54		IS_ON=/bin/true
55		if test -f /etc/init.d/functions; then
56			. /etc/init.d/functions
57			ECHO=echo
58			ECHO_OK="echo_success"
59			ECHO_ERROR="echo_failure"
60		else
61			ECHO=echo
62			ECHO_OK=:
63			ECHO_ERROR=:
64		fi
65		;;
66
67	*)
68		IS_ON=/bin/true
69		ECHO=echo
70		ECHO_OK=:
71		ECHO_ERROR=:
72		;;
73esac
74
75#### OS-Independent Stuff
76
77#
78# Set the timezone, if possible...  This allows the scheduler and
79# all child processes to know the local timezone when reporting
80# dates and times to the user.  If no timezone information is
81# found, then Greenwich Mean Time (GMT) will probably be used.
82#
83
84for file in /etc/TIMEZONE /etc/rc.config /etc/sysconfig/clock; do
85	if test -f $file; then
86	        . $file
87	fi
88done
89
90if test "x$ZONE" != x; then
91	TZ="$ZONE"
92fi
93
94if test "x$TIMEZONE" != x; then
95	TZ="$TIMEZONE"
96fi
97
98if test "x$TZ" != x; then
99	export TZ
100fi
101
102#
103# Don't use TMPDIR environment variable from init script, as that can
104# cause cupsd to set TempDir to a user's temporary directory instead
105# of the default...
106#
107
108unset TMPDIR
109
110
111#
112# Make sure we have the standard program directories in the path
113# since some operating systems don't provide a standard path on boot-up...
114#
115
116if test "x$PATH" = x; then
117	PATH="/bin:/usr/bin:/sbin:/usr/sbin"
118else
119	PATH="/bin:/usr/bin:/sbin:/usr/sbin:$PATH"
120fi
121
122export PATH
123
124#
125# See if the CUPS server (cupsd) is running...
126#
127
128case "`uname`" in
129	SunOS*)
130		pid=`ps -e | nawk '{if (match($4, ".*/cupsd$") || $4 == "cupsd") print $1}'`
131		;;
132	Linux* | *BSD* | Darwin*)
133		pid=`ps ax | awk '{if (match($5, ".*/cupsd$") || $5 == "cupsd") print $1}'`
134		;;
135	*)
136		pid=""
137		;;
138esac
139
140#
141# Start or stop the CUPS server based upon the first argument to the script.
142#
143
144case $1 in
145	start | restart | reload)
146		if $IS_ON cups; then
147			if test -x /sbin/portrelease; then
148				/sbin/portrelease cups
149			fi
150
151			if test "$pid" != ""; then
152				kill -HUP $pid
153			else
154				prefix=@prefix@
155				exec_prefix=@exec_prefix@
156				@sbindir@/cupsd
157				if test $? != 0; then
158					$ECHO_FAIL
159					$ECHO "cups: unable to $1 scheduler."
160					exit 1
161				fi
162			fi
163			$ECHO_OK
164			$ECHO "cups: ${1}ed scheduler."
165		fi
166		;;
167
168	stop)
169		if test "$pid" != ""; then
170			kill $pid
171			$ECHO_OK
172			$ECHO "cups: stopped scheduler."
173		fi
174		;;
175
176	status)
177		if test "$pid" != ""; then
178			echo "cups: scheduler is running."
179		else
180			echo "cups: scheduler is not running."
181		fi
182		;;
183
184	*)
185		echo "Usage: cups {reload|restart|start|status|stop}"
186		exit 1
187		;;
188esac
189
190#
191# Exit with no errors.
192#
193
194exit 0
195