View | Details | Raw Unified | Return to bug 247247
Collapse All | Expand All

(-)etc/rc.d/squid (-78 / +116 lines)
Lines 1-148 Link Here
1
#!/bin/sh
1
#!/bin/sh
2
#
2
#
3
# $FreeBSD: branches/2020Q2/www/squid/files/squid.in 474197 2018-07-08 20:46:45Z swills $
3
# $FreeBSD: branches/2020Q2/www/squid/files/squid.in 474197 2018-07-08 20:46:45Z swills $
4
#
4
#
5
# PROVIDE: squid
5
# PROVIDE: squid
6
# REQUIRE: LOGIN
6
# REQUIRE: NETWORKING kdc
7
# KEYWORD: shutdown
7
# KEYWORD: shutdown
8
#
8
#
9
# Note:
9
# To enable Squid, type (in a console)
10
# Set "squid_enable=yes" in either /etc/rc.conf, /etc/rc.conf.local or
10
#	'service squid enable'
11
# /etc/rc.conf.d/squid to activate Squid.
11
# or	'sysrc [-f /etc/rc.conf.local] squid_enable=yes'
12
#
12
#
13
# Additional variables you can define in one of these files:
13
# NOTE	'kdc' is not required to run Squid, but if Squid uses Kerberos,
14
#	the addition in REQUIRE ashures they are started in the right order.
14
#
15
#
15
# squid_chdir:	the directory into which the rc system moves into before
16
# Additional variables you can define in one of $rc_conf_files
16
# 		starting Squid. Default: /var/squid
17
# (/etc/rc.conf[.local] & {/usr/local}/etc/rc.conf.d/$name):
18
# to see them all, type 'sysrc squid rcvar', and to set one: 'sysrc var=value'
17
#
19
#
18
# squid_conf:	The configuration file that Squid should use.
19
#		Default: /usr/local/etc/squid/squid.conf
20
#
21
# squid_fib:	The alternative routing table id that Squid should use.
22
#		Default: none
23
#		See setfib(1) for further details. Note that the setfib(2)
24
#		system call is not available in FreeBSD versions prior to 7.1.
25
#
26
# squid_user:	The user id that should be used to run the Squid master
27
#		process. Default: squid.
28
#		Note that you probably need to define "squid_user=root" if
29
#		you want to run Squid in reverse proxy setups or if you want
30
#		Squid to listen on a "privileged" port < 1024.
31
#
32
# squid_pidfile:
33
#		The name (including the full path) of the Squid
34
#		master process' PID file.
35
#		Default: /var/run/squid/squid.pid.
36
#		You only need to change this if you changed the
37
#		corresponding entry in your Squid configuration.
38
#
39
# squid_flags:	Additional commandline arguments for Squid you might want to
40
#		use. See squid(8) for further details.
41
#
42
# squid_krb5_ktname:
43
#		Alternative Kerberos 5 Key Table.
44
#		Default: none
45
# squid_krb5_config:
46
#		Alternative Kerberos 5 config file
47
#		Default: none
48
49
. /etc/rc.subr
20
. /etc/rc.subr
50
21
51
name=squid
22
name=squid
52
rcvar=squid_enable
23
rcvar=squid_enable
53
54
# Make sure that we invoke squid with "-f ${squid_conf}"; define this
55
# variable early so reload_cmd and stop_precmd pick it up:
56
57
extra_commands="reload configtest"
24
extra_commands="reload configtest"
25
desc="(forward & reverse) HTTP/HTTPS/FTP caching proxy"
58
reload_cmd=squid_reload
26
reload_cmd=squid_reload
59
start_precmd=squid_prestart
27
start_precmd=squid_prestart
60
start_postcmd=squid_getpid
28
start_postcmd=squid_getpid
61
stop_precmd=squid_prestop
29
stop_precmd=squid_prestop
62
configtest_cmd=squid_configtest
30
configtest_cmd=squid_configtest
63
reload_precmd=squid_configtest
31
reload_precmd=squid_configtest
64
restart_precmd=squid_configtest
32
restart_precmd=squid_configtest
65
33
66
# squid(8) will not start if ${squid_conf} is not present so try
34
rc_debug="yes"
67
# to catch that beforehand via ${required_files} rather than make
35
rc_info="yes"
68
# squid(8) crash.
69
36
70
squid_load_rc_config()
37
# setup_vars() - set rc.subr(8) vars & defaults /before/ load_rc_config()
38
#squid_setup_vars()
39
#{
40
#local _var
41
42
set_rcvar ${name}_enable	NO \
43
	"To enable $name, use	'service ${name} enable'^^
44
	or			'sysrc ${name}_enable=yes'^^
45
	To start $name, use 'service $name start'"
46
set_rcvar ${name}_program	/usr/local/sbin/${name}
47
set_rcvar ${name}_chdir		/var/${name} "$name's working (home) directory"
48
set_rcvar ${name}_conf		/usr/local/etc/${name}/${name}.conf \
49
	"$name's configuration file"
50
set_rcvar ${name}_user		${name} \
51
	"${name}'s user id that runs the master process.^^
52
	NOTE that you most probably need to define '${name}_user=root'^^
53
	if you want to run $name in reverse proxy setups^^
54
	or if you want $name to listen on a privileged port < 1024."
55
set_rcvar ${name}_flags		NONE \
56
	"Additional command line arguments for $name.^^
57
	See ${name}(8) for further details.^^
58
	NOTE '-f \\\$${name}_conf' is always appended and can be ommited."
59
set_rcvar ${name}_maxwait	15 \
60
	"Max. time [seconds] to wait for $name to start up"
61
set_rcvar ${name}_pidfile	/var/run/${name}/${name}.pid \
62
	"(OBSOLETE)^^
63
	Instead, it is read from $name's config file \\\$${name}_conf.^^
64
	This overrules the default and any setting in^^
65
	\\\$rc_conf_files (and {/usr/local}/etc/rc.conf.d/$name)."
66
set_rcvar ${name}_fib		NONE \
67
	"The alternative routing table id for $name.^^
68
	See setfib(1) for further details. Note that the setfib(2)^^
69
	system call is not available in FreeBSD versions prior to 7.1."
70
set_rcvar ${name}_krb5_ktname	NONE "Alternative Kerberos 5 Key Table"
71
set_rcvar ${name}_krb5_config	NONE "Alternative Kerberos 5 config file"
72
#}
73
74
# setup_config() - /after/ our settings are read via load_rc_config()
75
squid_setup_config()
71
{
76
{
72
	: ${squid_chdir:=/var/squid}
77
	# rc.subr(8):get_pidfile_from_conf() uses this variable:
73
	: ${squid_conf:=/usr/local/etc/squid/squid.conf}
78
	local _pidfile_from_conf
74
	: ${squid_enable:=NO}
79
	local _var
75
	: ${squid_program:=/usr/local/sbin/squid}
76
	: ${squid_pidfile:=/var/run/squid/squid.pid}
77
	: ${squid_user:=squid}
78
80
79
	required_args="-f ${squid_conf}"
81
	# Squid will not start if $squid_conf is not present so try to catch
80
	required_dirs=$chdir
82
	# that beforehand via $required_files rather than make it crash.
81
	required_files=$squid_conf
83
	required_files=$squid_conf
82
	command_args="${required_args} ${squid_flags}"
84
83
#	We used to need it in squid3 to match pid and proc name
85
	# $pidfile: override default or setting from rc.conf
84
#	procname="?squid-*"
86
	if get_pidfile_from_conf "pid_filename" ${squid_conf} \
87
	&& [ -n "$_pidfile_from_conf" ]; then
88
		squid_pidfile=$_pidfile_from_conf
89
	fi
85
	pidfile=$squid_pidfile
90
	pidfile=$squid_pidfile
91
	piddir=$(dirname ${pidfile})
92
	for _var in dir file; do
93
		eval debug "pid${_var}=\$pid${_var}"
94
	done
95
	# Debug to check all went well - now the vars should be set
96
	for _var in enable program "chdir" conf user flags maxwait pidfile \
97
		fib kbr5_ktname krb5_config; do 
98
		eval debug "${name}_${_var}=\$${name}_${_var}"
99
	done
100
	required_dirs="${squid_chdir} ${piddir}"
101
102
	# Make sure that we invoke squid with "-f ${squid_conf}"; define
103
	# this variable early so reload_cmd and stop_precmd pick it up:
104
	required_args="-f ${squid_conf}"
105
106
	for _var in args dirs files; do
107
		eval debug "required_${_var}=\${required_${_var}}"
108
	done
109
	[ $squid_flags == "NONE" ] && squid_flags=""
110
	command_args="${squid_flags} ${required_args}"
111
	eval debug "command_args=\${command_args}"
112
113
	[ "${squid_fib}" == "NONE" ] && squid_fib=""
114
115
	# We used to need it in squid3 to match pid and proc name
116
	# procname="?squid-*"
86
}
117
}
87
118
119
# prestart() - setup shell environment, create files & directories, if needed.
88
squid_prestart()
120
squid_prestart()
89
{
121
{
90
	# setup KRB5_KTNAME:
122
	# if squid runs as non-root, we need to create the $pidfile
91
	squid_krb5_ktname=${squid_krb5_ktname:-"NONE"}
123
	# XXX done by service(8) via required_dirs?
124
	# [ -d $piddir ] || mkdir $piddir
125
	info "creating pidfile: $pidfile"
126
	[ -f $pidfile ] || touch $pidfile
127
128
	# the $piddir must be empty and should be owned by $squid_user
129
	chown $squid_user $pidfile
130
	chmod 600 $pidfile
131
132
	squid_configtest
133
92
	if [ "${squid_krb5_ktname}" != "NONE" ]; then
134
	if [ "${squid_krb5_ktname}" != "NONE" ]; then
93
		export KRB5_KTNAME=${squid_krb5_ktname}
135
		export KRB5_KTNAME=${squid_krb5_ktname}
94
	fi
136
	fi
95
96
	# setup KRB5_CONFIG:
97
	squid_krb5_config=${squid_krb5_config:-"NONE"}
98
	if [ "${squid_krb5_config}" != "NONE" ]; then
137
	if [ "${squid_krb5_config}" != "NONE" ]; then
99
		export KRB5_CONFIG=${squid_krb5_config}
138
		export KRB5_CONFIG=${squid_krb5_config}
100
	fi
139
	fi
101
140
	# setup FIB tables
102
	# setup FIB tables:
103
	if command -v check_namevarlist > /dev/null 2>&1; then
141
	if command -v check_namevarlist > /dev/null 2>&1; then
104
		check_namevarlist fib && return 0
142
		check_namevarlist fib && return 0
105
	fi
143
	fi
106
107
	${SYSCTL} net.fibs >/dev/null 2>&1 || return 0
144
	${SYSCTL} net.fibs >/dev/null 2>&1 || return 0
108
145
109
	squid_fib=${squid_fib:-"NONE"}
146
	if [ -n "${squid_fib}" ]; then
110
	if [ "${squid_fib}" != "NONE" ]; then
111
		command="setfib -F $squid_fib $command"
147
		command="setfib -F $squid_fib $command"
112
	else
113
		return 0
114
	fi
148
	fi
115
116
	squid_configtest
117
}
149
}
118
150
119
squid_reload()
151
squid_reload()
120
{
152
{
121
	$command $required_args $squid_flags -k reconfigure
153
	$command $command_args -k reconfigure
122
}
154
}
123
155
124
squid_configtest()
156
squid_configtest()
125
{
157
{
126
	echo "Performing sanity check on ${name} configuration."
158
	info "Performing sanity check on ${name} configuration."
127
	if $command $required_args $squid_flags -k check; then
159
	if $command $command_args -k check; then
128
		echo "Configuration for ${name} passes."
160
		info "Configuration for ${name} is ok."
129
		return 0
161
		return 0
130
	else
162
	else
131
		return $?
163
		return $?
132
	fi
164
	fi
133
}
165
}
134
166
167
# squid_getpid() - wait for squid to start up completely
135
squid_getpid()
168
squid_getpid()
136
{
169
{
137
	# retrieve the PID of the Squid master process explicitly here
138
	# in case rc.subr was unable to determine it:
139
	if [ -z "$rc_pid" ]; then
170
	if [ -z "$rc_pid" ]; then
171
		local _secs=0
140
		while ! [ -f ${pidfile} ]; do
172
		while ! [ -f ${pidfile} ]; do
173
			if [ $squid_maxwait -le $_secs ]; then
174
				warn "giving up"
175
				break;
176
			fi
141
			sleep 1
177
			sleep 1
178
			echo -n "."
179
			: $((_secs+=1))
142
		done
180
		done
143
		read _pid _junk <${pidfile}
181
		read _pid _junk <${pidfile}
144
		[ -z "${_pid}" ] || pid=${_pid}
182
		[ -z "${_pid}" ] || pid=${_pid}
145
	else
183
	else
146
		pid=${rc_pid}
184
		pid=${rc_pid}
147
	fi
185
	fi
148
}
186
}
Lines 150-158 Link Here
150
squid_prestop()
188
squid_prestop()
151
{
189
{
152
	command_args="$command_args -k shutdown"
190
	command_args="$command_args -k shutdown"
153
	squid_configtest
191
	squid_configtest
154
}
192
}
155
193
156
load_rc_config $name
194
load_rc_config $name
157
squid_load_rc_config
195
squid_setup_config
158
run_rc_command $1
196
run_rc_command $1

Return to bug 247247