]> git.pld-linux.org Git - packages/squid.git/blob - squid.init
- check config before restart
[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 start() {
62         # Check if the service is already running?
63         if [ ! -f /var/lock/subsys/squid ]; then
64                 msg_starting Squid
65                 daemon squid $SQUID_OPTS
66                 RETVAL=$?
67                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/squid
68         else
69                 msg_already_running Squid
70         fi
71 }
72
73 stop() {
74         if [ -f /var/lock/subsys/squid ]; then
75                 # Stop daemons.
76                 msg_stopping Squid
77                 if [ -f /var/run/squid.pid ]; then
78                         PID=$(filter_chroot $(cat /var/run/squid.pid))
79                         if [ -z "$PID" ]; then
80                                 PID=0
81                         fi
82                 else
83                         PID=0
84                 fi
85                 killproc squid
86                 RETVAL=$?
87                 if [ $PID != 0 ]; then
88                         show "Waiting for Squid to stop"
89                         busy
90                         timeout=0
91                         while ps -U squid -o user | grep -q ^squid
92                         do
93                                 if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
94                                     break
95                                 fi
96                                 sleep 1
97                                 timeout=$((timeout + 1))
98                         done
99                         ok
100                 fi
101                 rm -f /var/lock/subsys/squid >/dev/null 2>&1
102         else
103                 msg_not_running Squid
104         fi
105 }
106
107 # check that squid config is ok
108 # NOTE: needs running squid
109 configtest() {
110         show "Checking squid config syntax"
111         squid -k check
112         RETVAL=$?
113         [ $RETVAL = 0 ] && ok || fail
114 }
115
116 reload() {
117         if [ -f /var/lock/subsys/squid ]; then
118                 msg_reloading Squid
119                 busy
120                 squid -k reconfigure
121                 RETVAL=$?
122                 [ $RETVAL -ne 0 ] && RETVAL=7
123                 [ $RETVAL -eq 0 ] && ok || fail
124         else
125                 msg_not_running Squid
126                 exit 7
127         fi
128 }
129
130 restart() {
131         # if service is up, do configtest
132         if [ -f /var/lock/subsys/squid ]; then
133                 configtest
134                 if [ $RETVAL != 0 ]; then
135                         exit 1
136                 fi
137         fi
138         stop
139         start
140 }
141
142 RETVAL=0
143 # See how we were called.
144 case "$1" in
145   start)
146         start
147         ;;
148   stop)
149         stop
150         ;;
151   restart|force-reload)
152         restart
153         ;;
154   reload)
155         reload
156         ;;
157   status)
158         status squid
159         exit $?
160         ;;
161   init)
162         nls "Initializing %s" squid
163         squid -z
164         ;;
165   *)
166         msg_usage "$0 {start|stop|init|restart|reload|force-reload|status}"
167         exit 3
168 esac
169
170 exit $RETVAL
This page took 0.289249 seconds and 4 git commands to generate.