]> git.pld-linux.org Git - packages/squid.git/blob - squid.init
do not use builder's CPU instruction set, leads to SIGILL on older x86_64
[packages/squid.git] / squid.init
1 #!/bin/sh
2 #
3 # squid         This shell script takes care of starting and stopping
4 #               Squid Internet Object Cache
5 #
6 # chkconfig:    345 90 10
7 #
8 # description:  Squid - Internet Object Cache. Internet object caching is \
9 #               a way to store requested Internet objects (i.e., data \
10 #               available via the HTTP, FTP, and gopher protocols) on a \
11 #               system closer to the requesting site than to the source. \
12 #               Web browsers can then use the local Squid cache as a proxy \
13 #               HTTP server, reducing access time as well as bandwidth \
14 #               consumption.
15 # description(es): Squid - Cache de Objetos de Internet.  Cache de objetos \
16 #               es una manera de almacenar objetos Internet (i.e. Datos \
17 #               disponibles vía protocolos HTTP, FTP y gopher) en un \
18 #               sistema más próximo al site solicitador que el sistema \
19 #               original en internet.  Navegadores www pueden usar el \
20 #               cache squid local como un servidor proxy HTTP, reduciendo \
21 #               tanto el tiempo de acceso así como el consumo de banda de \
22 #               comunicación.
23 # description(pt_BR): Squid - Cache de Objetos da Internet. Cache de objetos \
24 #               é uma maneira de armazenar objetos Internet (i.e. dados \
25 #               disponíveis via protocolos HTTP, FTP e gopher) em um \
26 #               sistema mais próximo ao site requisitante do que o sistema \
27 #               original na internet. Navegadores www podem usar o cache \
28 #               squid local como um servidor proxy HTTP, reduzindo o tempo \
29 #               de acesso bem como o consumo de banda de comunicação.
30 #
31 # pidfile:      /var/run/squid.pid
32 # config:       /etc/squid/squid.conf
33
34
35 # Source function library
36 . /etc/rc.d/init.d/functions
37
38 # Get network config
39 . /etc/sysconfig/network
40
41 # Get service config
42 [ -f /etc/sysconfig/squid ] && . /etc/sysconfig/squid
43
44 # Check that networking is up.
45 if is_yes "${NETWORKING}"; then
46         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then
47                 msg_network_down Squid
48                 exit 1
49         fi
50 else
51         exit 0
52 fi
53
54 # Set default shutdown timeout if it is not set in service config
55 SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-60}
56
57 # determine which one is the cache_swap directory
58 CACHE_SWAP=$(awk '/^cache_dir/{print $3}' /etc/squid/squid.conf)
59 [ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/cache/squid
60
61 check_cache_dirs() {
62         local need_init=0 dir
63         for dir in $CACHE_SWAP; do
64                 if [ ! -d $dir/00 ]; then
65                         need_init=1
66                 fi
67         done
68         if [ $need_init = 1 ]; then
69                 show "Initializing Squid cache dirs"
70                 squid -z -F -D >> /var/log/squid/squid.out 2>&1 && ok || fail
71         fi
72 }
73
74 start() {
75         # Check if the service is already running?
76         if [ ! -f /var/lock/subsys/squid ]; then
77                 check_cache_dirs
78                 msg_starting Squid
79                 daemon /usr/sbin/squid $SQUID_OPTS
80                 RETVAL=$?
81                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/squid
82         else
83                 msg_already_running Squid
84         fi
85 }
86
87 stop() {
88         if [ -f /var/lock/subsys/squid ]; then
89                 # Stop daemons.
90                 msg_stopping Squid
91                 killproc squid
92
93                 if [ -f /var/run/squid.pid ]; then
94                         show "Waiting for Squid to stop"
95                         busy
96
97                         timeout=0
98                         while : ; do
99                                 [ ! -f /var/run/squid.pid ] || break
100                                 if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
101                                         RETVAL=1
102                                         break
103                                 fi
104                                 sleep 1 && echo -n "."
105                                 timeout=$((timeout+1))
106                         done
107                         ok
108                 fi
109
110                 rm -f /var/lock/subsys/squid >/dev/null 2>&1
111         else
112                 msg_not_running Squid
113         fi
114 }
115
116 # check that squid config is ok
117 configtest() {
118         show "Checking squid config syntax"
119         squid -k parse >> /var/log/squid/squid.out 2>&1
120         RETVAL=$?
121         [ $RETVAL = 0 ] && ok || fail
122 }
123
124 reload() {
125         if [ -f /var/lock/subsys/squid ]; then
126                 msg_reloading Squid
127                 busy
128                 squid -k reconfigure
129                 RETVAL=$?
130                 [ $RETVAL -ne 0 ] && RETVAL=7
131                 [ $RETVAL -eq 0 ] && ok || fail
132         else
133                 msg_not_running Squid
134                 exit 7
135         fi
136 }
137
138 restart() {
139         # if service is up, do configtest
140         if [ -f /var/lock/subsys/squid ]; then
141                 configtest
142                 if [ $RETVAL != 0 ]; then
143                         exit 1
144                 fi
145         fi
146         stop
147         start
148 }
149
150 condrestart() {
151         # if service is up, do configtest
152         if [ -f /var/lock/subsys/squid ]; then
153                 configtest
154                 if [ $RETVAL != 0 ]; then
155                         exit 1
156                 fi
157                 stop
158                 start
159         else
160                 msg_not_running Squid
161                 RETVAL=0
162         fi
163 }
164
165 RETVAL=0
166 # See how we were called.
167 case "$1" in
168   start)
169         start
170         ;;
171   stop)
172         stop
173         ;;
174   restart)
175         restart
176         ;;
177   try-restart)
178         condrestart
179         ;;
180   reload|force-reload)
181         reload
182         ;;
183   status)
184         status squid
185         exit $?
186         ;;
187   init)
188         show "Initializing Squid"; echo
189         check_cache_dirs
190         ;;
191   *)
192         msg_usage "$0 {start|stop|init|restart|try-restart|reload|force-reload|status}"
193         exit 3
194 esac
195
196 exit $RETVAL
This page took 0.096967 seconds and 3 git commands to generate.