Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#!/bin/bash
2
# chkconfig: - 90 25
3
# pidfile: /var/run/squid.pid
4
# config: /etc/squid/squid.conf
5
#
6
### BEGIN INIT INFO
7
# Provides: squid
8
# Short-Description: starting and stopping Squid Internet Object Cache
9
# Description: Squid - Internet Object Cache. Internet object caching is \
10
#       a way to store requested Internet objects (i.e., data available \
11
#       via the HTTP, FTP, and gopher protocols) on a system closer to the \
12
#       requesting site than to the source. Web browsers can then use the \
13
#       local Squid cache as a proxy HTTP server, reducing access time as \
14
#       well as bandwidth consumption.
15
### END INIT INFO
16
 
17
 
18
PATH=/usr/bin:/sbin:/bin:/usr/sbin
19
export PATH
20
 
21
# Source function library.
22
. /etc/rc.d/init.d/functions
23
 
24
# Source networking configuration.
25
. /etc/sysconfig/network
26
 
27
if [ -f /etc/sysconfig/squid ]; then
28
	. /etc/sysconfig/squid
29
fi
30
 
31
# don't raise an error if the config file is incomplete
32
# set defaults instead:
33
SQUID_OPTS=${SQUID_OPTS:-""}
34
SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
35
SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
36
SQUID_CONF=${SQUID_CONF:-"/etc/squid/squid.conf"}
37
 
38
# determine the name of the squid binary
39
[ -f /usr/sbin/squid ] && SQUID=squid
40
 
41
prog="$SQUID"
42
 
43
# determine which one is the cache_swap directory
44
CACHE_SWAP=`sed -e 's/#.*//g' $SQUID_CONF | \
45
	grep cache_dir | awk '{ print $3 }'`
46
 
47
RETVAL=0
48
 
49
probe() {
50
	# Check that networking is up.
51
	[ ${NETWORKING} = "no" ] && exit 1
52
 
53
	[ `id -u` -ne 0 ] && exit 4
54
 
55
	# check if the squid conf file is present
56
	[ -f $SQUID_CONF ] || exit 6
57
}
58
 
59
start() {
60
	probe
61
 
62
	parse=`$SQUID -k parse -f $SQUID_CONF 2>&1`
63
	RETVAL=$?
64
	if [ $RETVAL -ne 0 ]; then
65
		echo -n $"Starting $prog: "
66
		echo_failure
67
		echo
68
		echo "$parse"
69
		return 1
70
	fi
71
	for adir in $CACHE_SWAP; do
72
		if [ ! -d $adir/00 ]; then
73
			echo -n "init_cache_dir $adir... "
74
			$SQUID -z -F -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1
75
		fi
76
	done
77
	echo -n $"Starting $prog: "
78
	$SQUID $SQUID_OPTS -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1
79
	RETVAL=$?
80
	if [ $RETVAL -eq 0 ]; then
81
		timeout=0;
82
		while : ; do
83
			[ ! -f /var/run/squid.pid ] || break
84
			if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then
85
				RETVAL=1
86
				break
87
			fi
88
			sleep 1 && echo -n "."
89
			timeout=$((timeout+1))
90
		done
91
	fi
92
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID
93
	[ $RETVAL -eq 0 ] && echo_success
94
	[ $RETVAL -ne 0 ] && echo_failure
95
	echo
96
	return $RETVAL
97
}
98
 
99
stop() {
100
	echo -n $"Stopping $prog: "
101
	$SQUID -k check -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1
102
	RETVAL=$?
103
	if [ $RETVAL -eq 0 ] ; then
104
		$SQUID -k shutdown -f $SQUID_CONF &
105
		rm -f /var/lock/subsys/$SQUID
106
		timeout=0
107
		while : ; do
108
			[ -f /var/run/squid.pid ] || break
109
			if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
110
				echo
111
				return 1
112
			fi
113
			sleep 2 && echo -n "."
114
			timeout=$((timeout+2))
115
		done
116
		echo_success
117
		echo
118
	else
119
		echo_failure
120
		if [ ! -e /var/lock/subsys/$SQUID ]; then
121
			RETVAL=0
122
		fi
123
		echo
124
	fi
125
	return $RETVAL
126
}
127
 
128
reload() {
129
	$SQUID $SQUID_OPTS -k reconfigure -f $SQUID_CONF
130
}
131
 
132
restart() {
133
	stop
134
	start
135
}
136
 
137
condrestart() {
138
	[ -e /var/lock/subsys/squid ] && restart || :
139
}
140
 
141
rhstatus() {
142
	status $SQUID && $SQUID -k check -f $SQUID_CONF
143
}
144
 
145
 
146
case "$1" in
147
start)
148
	start
149
	;;
150
 
151
stop)
152
	stop
153
	;;
154
 
155
reload|force-reload)
156
	reload
157
	;;
158
 
159
restart)
160
	restart
161
	;;
162
 
163
condrestart|try-restart)
164
	condrestart
165
	;;
166
 
167
status)
168
	rhstatus
169
	;;
170
 
171
probe)
172
	probe
173
	;;
174
 
175
*)
9 - 176
	echo $"Usage: $0 {start|stop|status|reload|force-reload|restart|condrestart|try-restart|probe}"
4 - 177
	exit 2
178
esac
179
 
180
exit $?