]> git.pld-linux.org Git - packages/squid.git/blobdiff - squid.init
- enabled eCAP support
[packages/squid.git] / squid.init
index 72686bf57ba111c66bd53d9e161efed2800eaae0..b09f17a2810312e40a256538ea8e1ef6e4cec825 100644 (file)
@@ -58,11 +58,25 @@ SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-60}
 CACHE_SWAP=$(awk '/^cache_dir/{print $3}' /etc/squid/squid.conf)
 [ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/cache/squid
 
+check_cache_dirs() {
+       local need_init=0 dir
+       for dir in $CACHE_SWAP; do
+               if [ ! -d $dir/00 ]; then
+                       need_init=1
+               fi
+       done
+       if [ $need_init = 1 ]; then
+               show "Initializing Squid cache dirs"
+               squid -z -F -D >> /var/log/squid/squid.out 2>&1 && ok || fail
+       fi
+}
+
 start() {
        # Check if the service is already running?
        if [ ! -f /var/lock/subsys/squid ]; then
+               check_cache_dirs
                msg_starting Squid
-               daemon squid $SQUID_OPTS
+               daemon /usr/sbin/squid $SQUID_OPTS
                RETVAL=$?
                [ $RETVAL -eq 0 ] && touch /var/lock/subsys/squid
        else
@@ -74,30 +88,25 @@ stop() {
        if [ -f /var/lock/subsys/squid ]; then
                # Stop daemons.
                msg_stopping Squid
-               if [ -f /var/run/squid.pid ]; then
-                       PID=$(filter_chroot $(cat /var/run/squid.pid))
-                       if [ -z "$PID" ]; then
-                               PID=0
-                       fi
-               else
-                       PID=0
-               fi
                killproc squid
-               RETVAL=$?
-               if [ $PID != 0 ]; then
+
+               if [ -f /var/run/squid.pid ]; then
                        show "Waiting for Squid to stop"
                        busy
+
                        timeout=0
-                       while ps -U squid -o user | grep -q ^squid
-                       do
+                       while : ; do
+                               [ ! -f /var/run/squid.pid ] || break
                                if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
-                                   break
+                                       RETVAL=1
+                                       break
                                fi
-                               sleep 1
-                               timeout=$((timeout + 1))
+                               sleep 1 && echo -n "."
+                               timeout=$((timeout+1))
                        done
                        ok
                fi
+
                rm -f /var/lock/subsys/squid >/dev/null 2>&1
        else
                msg_not_running Squid
@@ -105,10 +114,9 @@ stop() {
 }
 
 # check that squid config is ok
-# NOTE: needs running squid
 configtest() {
        show "Checking squid config syntax"
-       squid -k check
+       squid -k parse >> /var/log/squid/squid.out 2>&1
        RETVAL=$?
        [ $RETVAL = 0 ] && ok || fail
 }
@@ -139,6 +147,21 @@ restart() {
        start
 }
 
+condrestart() {
+       # if service is up, do configtest
+       if [ -f /var/lock/subsys/squid ]; then
+               configtest
+               if [ $RETVAL != 0 ]; then
+                       exit 1
+               fi
+               stop
+               start
+       else
+               msg_not_running Squid
+               RETVAL=0
+       fi
+}
+
 RETVAL=0
 # See how we were called.
 case "$1" in
@@ -148,10 +171,13 @@ case "$1" in
   stop)
        stop
        ;;
-  restart|force-reload)
+  restart)
        restart
        ;;
-  reload)
+  try-restart)
+       condrestart
+       ;;
+  reload|force-reload)
        reload
        ;;
   status)
@@ -159,11 +185,11 @@ case "$1" in
        exit $?
        ;;
   init)
-       nls "Initializing %s" squid
-       squid -z
+       show "Initializing Squid"; echo
+       check_cache_dirs
        ;;
   *)
-       msg_usage "$0 {start|stop|init|restart|reload|force-reload|status}"
+       msg_usage "$0 {start|stop|init|restart|try-restart|reload|force-reload|status}"
        exit 3
 esac
 
This page took 0.047072 seconds and 4 git commands to generate.