summaryrefslogtreecommitdiff
path: root/network/squid/rc.squid.new
blob: 4810dae64f1230076a30a412d36349892744e5e3 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
# Start/stop/restart/reload the Squid Internet Object Cache (squid)
# To make Squid start automatically at boot, make this
# file executable:  chmod 755 /etc/rc.d/rc.Squid
#
# Written for Slackware Linux by Erik Jan Tromp
# Modified by David Somero <xgizzmo@slackbuilds.org>

SQUIDCFG=/etc/squid/squid.conf
SQUIDCMD=/usr/sbin/squid

if [ ! -r $SQUIDCFG ]; then
  echo "Please set the correct path to $SQUIDCFG"
  exit 1
fi

if [ ! -x $SQUIDCMD ]; then
  echo "$SQUIDCMD not found"
  exit 1
fi

squid_start() {
  # Create cache directory hierarchy if needed
  ALL_DIRS=$(awk '/^cache_dir/ {print $3}' $SQUIDCFG)
  [ -z "$ALL_DIRS" ] && ALL_DIRS=/var/cache/squid

  for CACHE_DIR in $ALL_DIRS ; do
    if [ ! -d $CACHE_DIR/00 ] ; then
      echo "Creating swap directories:  $SQUIDCMD -z"
      $SQUIDCMD -z 2> /dev/null
      break
    fi
  done

  echo "Starting Squid:  $SQUIDCMD -DF"
  $SQUIDCMD -DF
}

squid_stop() {
  COUNTDOWN=$(awk '/^shutdown_lifetime/ {print $2}' $SQUIDCFG)
  [ -z "$COUNTDOWN" ] && COUNTDOWN=30

  echo -n "Shutting down Squid in $COUNTDOWN seconds:  "
  $SQUIDCMD -k shutdown 2> /dev/null
  while $SQUIDCMD -k check 2> /dev/null ; do
    sleep 1
    echo -n .
    COUNTDOWN=$[ $COUNTDOWN - 1 ]
    if [ $COUNTDOWN -le 0 ] ; then
      $SQUIDCMD -k interrupt 2> /dev/null
      sleep 1
      break
    fi
  done
  echo
}

squid_restart() {
  squid_stop
  sleep 1
  squid_start
}

squid_reload() {
  $SQUIDCMD -k reconfigure 2> /dev/null
}

case "$1" in
'start')
  squid_start
  ;;
'stop')
  squid_stop
  ;;
'restart')
  squid_restart
  ;;
'reload')
  squid_reload
  ;;
*)
  echo "usage: $0 start|stop|restart|reload"
esac