~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to debian/clamav-freshclam.init.in

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mto: (0.35.3 sid)
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: james.westby@ubuntu.com-20080905172534-2lxrdzafr26tqfkx
Tags: 0.94.dfsg-1
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
 
 
3
### BEGIN INIT INFO
 
4
# Provides:          clamav-freshclam
 
5
# Required-Start:    $syslog
 
6
# Should-Start:      clamav-daemon
 
7
# Required-Stop:
 
8
# Should-Stop:       
 
9
# Default-Start:     2 3 4 5
 
10
# Default-Stop:      0 6
 
11
# Short-Description: ClamAV virus database updater
 
12
# Description:       Clam AntiVirus virus database updater
 
13
### END INIT INFO
 
14
 
 
15
DAEMON=/usr/bin/freshclam
 
16
NAME=freshclam
 
17
DESC="ClamAV virus database updater"
 
18
[ -x $DAEMON ] || exit 0
 
19
 
 
20
CLAMAV_CONF_FILE=/etc/clamav/clamd.conf
 
21
FRESHCLAM_CONF_FILE=/etc/clamav/freshclam.conf
 
22
PIDFILE=/var/run/clamav/freshclam.pid
 
23
[ -f /var/lib/clamav/interface ] && INTERFACE=`cat /var/lib/clamav/interface`
 
24
 
 
25
. /lib/lsb/init-functions
 
26
 
 
27
#COMMON-FUNCTIONS#
 
28
 
 
29
slurp_config "$FRESHCLAM_CONF_FILE"
 
30
 
 
31
[ -n "$PidFile" ] && PIDFILE="$PidFile"
 
32
[ -n "$DataBaseDirectory" ] || DataBaseDirectory=/var/run/clamav
 
33
 
 
34
make_dir "$DataBaseDirectory"
 
35
 
 
36
if [ -f "$PIDFILE" ]; then
 
37
  PID=`pidofproc -p $PIDFILE $DAEMON`
 
38
  RUNNING=$?
 
39
else
 
40
  PID=`pidofproc $DAEMON`
 
41
  RUNNING=$?
 
42
fi
 
43
 
 
44
handle_iface()
 
45
{
 
46
  OPTIND=1
 
47
  if  [ "$1" = "stop" ] && [ "$RUNNING" != 0 ]; then
 
48
    return 1
 
49
  elif [ "$1" = "start" ] && [ "$RUNNING" = 0 ]; then
 
50
    return 1
 
51
  else
 
52
    return 0
 
53
  fi
 
54
  
 
55
  IS_UP=0
 
56
  MATCH=0
 
57
  for inet in $INTERFACE; do
 
58
    route | grep -q "$inet" && IS_UP=`expr "$IS_UP" + 1`
 
59
    [ "$inet" = "$IFACE" ] && MATCH=1
 
60
  done
 
61
  
 
62
  if [ -n "$INTERFACE" ]; then         # Want if-up.d handling
 
63
    if [ -n "$IFACE" ]; then           # Called by if-up.d - for us
 
64
      if [ "$MATCH" = '1' ]; then      # IFACE is ours 
 
65
        if [ "$IS_UP" = '1' ]; then    # and is only one up
 
66
          return 0
 
67
        else                           # Either not up, or others are up
 
68
          return 1
 
69
        fi
 
70
      else                             # IFACE is not ours
 
71
        return 1
 
72
      fi
 
73
    else                               # Not called by if-up.d && $1='(stop|start)'
 
74
      return 1
 
75
    fi
 
76
  else                                 # No if-up.d handling - just return
 
77
    return 0
 
78
  fi
 
79
}
 
80
 
 
81
handle_iface $1 || exit 0
 
82
 
 
83
[ -z "$UpdateLogFile" ] && UpdateLogFile=/var/log/clamav/freshclam.log
 
84
[ -z "$DatabaseDirectory" ] && DatabaseDirectory=/var/lib/clamav/
 
85
[ -n "$DatabaseOwner" ] || DatabaseOwner=clamav
 
86
 
 
87
case "$1" in
 
88
  no-daemon)
 
89
  su "$DatabaseOwner" -p -s /bin/sh -c "freshclam -l $UpdateLogFile --datadir $DatabaseDirectory"
 
90
  ;;
 
91
  start)
 
92
  OPTIND=1
 
93
  log_daemon_msg "Starting $DESC" "$NAME"
 
94
  # If user wants it run from cron, we only accept no-daemon and stop
 
95
  if [ -f /etc/cron.d/clamav-freshclam ]; then
 
96
    log_warning_msg "Not starting $NAME - cron option selected"
 
97
    log_warning_msg "Run the init script with the 'no-daemon' option"
 
98
    log_end_msg 1
 
99
    exit 0
 
100
  fi
 
101
  su "$DatabaseOwner" -p -s /bin/sh -c ". /lib/lsb/init-functions && start_daemon $DAEMON -d --quiet"
 
102
  log_end_msg $?
 
103
  ;;
 
104
  stop)
 
105
  OPTIND=1
 
106
  log_daemon_msg "Stopping $DESC" "$NAME"
 
107
  if [ -n "$PID" ]; then
 
108
    kill -15 -"$PID"
 
109
    ret=$?
 
110
    sleep 1
 
111
    if kill -0 "$PID" 2>/dev/null; then
 
112
      ret=$?
 
113
      log_progress_msg "Waiting . "
 
114
      cnt=0
 
115
      while kill -0 "$PID" 2>/dev/null; do
 
116
        ret=$?
 
117
        cnt=`expr "$cnt" + 1`
 
118
        if [ "$cnt" -gt 15 ]; then
 
119
          kill -9 "$PID"
 
120
          ret=$?
 
121
          break
 
122
        fi
 
123
        sleep 2
 
124
        log_progress_msg ". "
 
125
      done
 
126
    fi
 
127
  else
 
128
    killproc -p $PIDFILE $DAEMON
 
129
    ret=$?
 
130
  fi
 
131
  log_end_msg $ret
 
132
  ;;
 
133
  restart|force-reload)
 
134
  $0 stop
 
135
  $0 start
 
136
  ;;
 
137
  reload-log)
 
138
  OPTIND=1
 
139
  log_daemon_msg "Reloading $DESC" "$NAME"
 
140
  if [ "$RUNNING" = 0 ] && [ -n "$PID" ]; then
 
141
    kill -HUP $PID
 
142
  fi
 
143
  log_end_msg $?
 
144
  ;;
 
145
  skip)
 
146
  ;;
 
147
  status)
 
148
  case "$RUNNING" in
 
149
    0) log_success_msg "$NAME is running."
 
150
    ;;
 
151
    1) log_warning_msg "$NAME is not running, but pidfile $PIDFILE exists."
 
152
    ;;
 
153
    3) log_failure_msg "$NAME is not running."
 
154
    ;;
 
155
    *) log_failure_msg "$NAME is unknown."
 
156
    ;;
 
157
  esac
 
158
  ;;
 
159
  *)
 
160
  log_failure_msg "Usage: $0 {no-daemon|start|stop|restart|force-reload|reload-log|skip|status}" >&2
 
161
  exit 1
 
162
  ;;
 
163
esac
 
164
 
 
165
exit 0
 
166