summaryrefslogtreecommitdiff
path: root/extra/squid/squid
blob: 2df1fc72d0000b8dab34774a4e8207e0b7c2da0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

# source application-specific settings
SQUID_ARGS=
[ -f /etc/conf.d/squid ] && . /etc/conf.d/squid

. /etc/rc.conf
. /etc/rc.d/functions

PID=`pidof -o %PPID /usr/sbin/squid`
case "$1" in

  start)
    if [ ! -f /var/cache/squid/swap.state ]; then
      stat_busy "Creating squid's swap directories"
      /usr/sbin/squid -z
    fi
    stat_busy "Starting squid"
    [ -z "$PID" ] && /usr/sbin/squid ${SQUID_ARGS}
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon squid
      stat_done
    fi
    ;;

  stop)
    stat_busy "Stopping squid"
    [ ! -z "$PID" ]  && /usr/sbin/squid -k shutdown &> /dev/null
    if [ $? -gt 0 ]; then
      stat_fail
    else
      # wait for squid to shutdown so we can safely do a restart
      while [ ! -z "`pidof -o %PPID /usr/sbin/squid`" ]; do
        stat_append "."
        sleep 3
      done
      rm_daemon squid
      stat_done
    fi
    ;;

  restart)
    $0 stop
    sleep 5
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"  
esac
exit 0