Skip to content

Commit c65b12c

Browse files
committed
lession.squid: add (similar) #squid.init file
1 parent eb36c41 commit c65b12c

File tree

2 files changed

+199
-1
lines changed

2 files changed

+199
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ that tries to clean up `squid`'s `PID` directory:
240240

241241
That is similar to this script
242242
https://github.com/mozilla-services/squid-rpm/blob/47880414f17affdbb634b6f0a19a342995fb60f6/SOURCES/squid.init,
243-
whose copy is in `examples/squid.init`. Because `RedHat` doesn't publish
243+
whose copy is in `examples/squid.init.sh`. Because `RedHat` doesn't publish
244244
their code, we can only _guess_ that they put `SQUID_PIDFILE_DIR` in some
245245
external configuration file (like `Debian` often uses `/etc/default/`),
246246
and for some `UNKNOWN` reason, `$SQUID_PIDFILE_DIR` is expanded to `empty`.

examples/squid.init.sh

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

0 commit comments

Comments
 (0)