summaryrefslogtreecommitdiff
blob: cdb0fdac41e9c9db9fe1c5ade0f667b6482e4181 (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
#!/sbin/runscript
# Copyright 1999-2002 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: /var/cvsroot/gentoo-x86/net-www/squid/files/squid.rc6,v 1.4 2002/02/08 09:58:06 woodchip Exp $

depend() {
	need net
}

maxfiledescriptors() {
	[ -n "$SQUID_MAXFD" ] || return
	[ -f /proc/sys/fs/file-max ] || return
	[ $SQUID_MAXFD -le 4096 ] || SQUID_MAXFD=4096
	global_file_max=`cat /proc/sys/fs/file-max`
	minimal_file_max=$(($SQUID_MAXFD + 4096))
	if [ "$global_file_max" -lt $minimal_file_max ] ; then
		echo $minimal_file_max > /proc/sys/fs/file-max
	fi
	ulimit -n $SQUID_MAXFD
}

checkconfig() {
	if [ ! -e /etc/squid/squid.conf ] ; then
		eerror "You need an /etc/squid/squid.conf to run squid"
		eerror "There is a sample file in /usr/share/doc/squid"
		return 1
	fi

	maxfiledescriptors

	CACHE_SWAP=`sed -e 's/#.*//g' /etc/squid/squid.conf | \
		grep cache_dir | awk '{ print $3 }'`
	[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/spool/squid
	cd /var/spool/squid ; umask 027
	for x in $CACHE_SWAP ; do
		if [ ! -d $x/00 ] ; then
			einfo "Initializing cache directory: $x"
			/usr/sbin/squid -z -F 2>/dev/null
			if [ $? -ne 0 ] ; then
				eerror "Error initializing: $x"
				return 1
			fi
		fi
	done
}

start() {
	checkconfig || return 1
	ebegin "Starting squid"
	start-stop-daemon --quiet --start --exec /usr/sbin/squid -- ${SQUID_OPTS}
	sleep 1
	eend $?
}

stop() {
	ebegin "Stopping squid"
	start-stop-daemon --stop --quiet --pidfile /var/run/squid.pid \
		--retry -0/5/-0/5/-0/10/-0/10/-9/10
	eend $?
}