~ubuntu-branches/ubuntu/precise/squid/precise

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
74
75
76
77
78
79
80
81
82
83
84
85
# squid - SQUID HTTP proxy-cache
#

description	"HTTP proxy-cache"
author		"Chuck Short <zulcss@ubuntu.com>"

# The second "or" condition is to start squid in case it failed to start
# because no real interface was there.
start on runlevel [2345]
stop on runlevel [!2345]

# Disable DNS checks so we can start squid
# before a "real" network is available.
env SQUID_ARGS="-D"

pre-start script
	if [ -f /etc/default/squid ]; then
		. /etc/default/squid
	fi


	grepconf () {
        	w="     " # space tab
        	sq=/etc/squid/squid.conf
        	# sed is cool.
        	res=`sed -ne '
                	s/^'$1'['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
                	t end;
                	d;
                :end q' < $sq`
        	[ -n "$res" ] || res=$2
		echo "$res"
	}

	grepconf2 () {
        	w="     " # space tab
        	sq=/etc/squid/squid.conf
        	# sed is cool.
        	res=`sed -ne '
                	s/^'$1'['"$w"']\+[^'"$w"']\+['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
                	t end;
                	d;
                :end q' < $sq`
        	[ -n "$res" ] || res=$2
        	echo "$res"
	}
	#
	# Try to increase the # of filedescriptors we can open.
	#
	maxfds () {
		[ -n "$SQUID_MAXFD" ] || return
		[ -f /proc/sys/fs/file-max ] || return 0
		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
	}

	cdr=`grepconf2 cache_dir /var/spool/squid`
	ctp=`grepconf cache_dir ufs`

	case "$cdr" in
		[0-9]*)
			echo "squid: squid.conf contains 2.2.5 syntax - not starting"
			exit 1 ; stop
		;;
	esac

	if [ -d "$cdr" -a ! -d "$cdr/00" ] || [ "$ctp" = "coss" -a ! -w "$cdr" ]
	then
		/usr/sbin/squid $SQUID_ARGS -z
	fi
	maxfds
end script

script
	if [ -f /etc/default/squid ]; then
		. /etc/default/squid
	fi

	exec /usr/sbin/squid -N $SQUID_ARGS
end script