]> git.pld-linux.org Git - packages/squid.git/commitdiff
- check config before restart
authorElan Ruusamäe <glen@pld-linux.org>
Fri, 23 Nov 2007 12:20:38 +0000 (12:20 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    squid.init -> 1.47

squid.init

index 8495da5368663d6f79f9d7d12da76d757257a831..72686bf57ba111c66bd53d9e161efed2800eaae0 100644 (file)
@@ -41,9 +41,6 @@
 # Get service config
 [ -f /etc/sysconfig/squid ] && . /etc/sysconfig/squid
 
-# Set default shutdown timeout if it is not set in service config
-SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-60}
-
 # Check that networking is up.
 if is_yes "${NETWORKING}"; then
        if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then
@@ -54,6 +51,13 @@ else
        exit 0
 fi
 
+# Set default shutdown timeout if it is not set in service config
+SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-60}
+
+# determine which one is the cache_swap directory
+CACHE_SWAP=$(awk '/^cache_dir/{print $3}' /etc/squid/squid.conf)
+[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/cache/squid
+
 start() {
        # Check if the service is already running?
        if [ ! -f /var/lock/subsys/squid ]; then
@@ -71,7 +75,7 @@ stop() {
                # Stop daemons.
                msg_stopping Squid
                if [ -f /var/run/squid.pid ]; then
-                       PID=$(filter_chroot `cat /var/run/squid.pid`)
+                       PID=$(filter_chroot $(cat /var/run/squid.pid))
                        if [ -z "$PID" ]; then
                                PID=0
                        fi
@@ -80,7 +84,7 @@ stop() {
                fi
                killproc squid
                RETVAL=$?
-               if [ ! $PID -eq 0 ]; then
+               if [ $PID != 0 ]; then
                        show "Waiting for Squid to stop"
                        busy
                        timeout=0
@@ -90,7 +94,7 @@ stop() {
                                    break
                                fi
                                sleep 1
-                               timeout=$((timeout+1))
+                               timeout=$((timeout + 1))
                        done
                        ok
                fi
@@ -100,6 +104,15 @@ stop() {
        fi
 }
 
+# check that squid config is ok
+# NOTE: needs running squid
+configtest() {
+       show "Checking squid config syntax"
+       squid -k check
+       RETVAL=$?
+       [ $RETVAL = 0 ] && ok || fail
+}
+
 reload() {
        if [ -f /var/lock/subsys/squid ]; then
                msg_reloading Squid
@@ -109,11 +122,23 @@ reload() {
                [ $RETVAL -ne 0 ] && RETVAL=7
                [ $RETVAL -eq 0 ] && ok || fail
        else
-               msg_not_running Squid >&2
+               msg_not_running Squid
                exit 7
        fi
 }
 
+restart() {
+       # if service is up, do configtest
+       if [ -f /var/lock/subsys/squid ]; then
+               configtest
+               if [ $RETVAL != 0 ]; then
+                       exit 1
+               fi
+       fi
+       stop
+       start
+}
+
 RETVAL=0
 # See how we were called.
 case "$1" in
@@ -124,8 +149,7 @@ case "$1" in
        stop
        ;;
   restart|force-reload)
-       stop
-       start
+       restart
        ;;
   reload)
        reload
This page took 0.039403 seconds and 4 git commands to generate.