~ubuntu-branches/ubuntu/trusty/clamav/trusty-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2005-09-19 09:05:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050919090559-hikpqduq8yx5qxo2
Tags: 0.87-1
* New upstream version
  - Fixes CAN-2005-2920 and CAN-2005-2919 (closes: #328660)
* New logcheck line for clamav-daemon (closes: #323132)
* relibtoolize and apply kfreebsd patch (closes: #327707)
* Make sure init.d script starts freshclam up again after upgrade when run
  from if-up.d (closes: #328912)

Show diffs side-by-side

added added

removed removed

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