~ubuntu-branches/ubuntu/saucy/clamav/saucy-backports

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman
  • Date: 2014-07-15 01:08:10 UTC
  • mfrom: (0.35.47 sid)
  • Revision ID: package-import@ubuntu.com-20140715010810-ru66ek4fun2iseba
Tags: 0.98.4+dfsg-2~ubuntu13.10.1
No-change backport to saucy (LP: #1341962)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
# Description:       Clam AntiVirus virus database updater
13
13
### END INIT INFO
14
14
 
 
15
# The exit status codes should comply with LSB.
 
16
# https://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
 
17
 
15
18
DAEMON=/usr/bin/freshclam
16
19
NAME=freshclam
17
20
DESC="ClamAV virus database updater"
 
21
 
 
22
# required by Debian policy 9.3.2
18
23
[ -x $DAEMON ] || exit 0
19
24
 
20
25
CLAMAV_CONF_FILE=/etc/clamav/clamd.conf
21
26
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
27
 
25
28
#COMMON-FUNCTIONS#
26
29
 
28
31
 
29
32
slurp_config "$FRESHCLAM_CONF_FILE"
30
33
 
31
 
[ -n "$PidFile" ] && PIDFILE="$PidFile"
 
34
if [ -z "$PidFile" ]
 
35
then
 
36
  log_failure_msg "$NAME: Can not continue with PidFile not set"
 
37
  if [ "$1" = "status" ]; then
 
38
    # program or service status is unknown
 
39
    exit 4;
 
40
  else
 
41
    # program is not configured correctly
 
42
    exit 6;
 
43
  fi
 
44
fi
32
45
[ -n "$DataBaseDirectory" ] || DataBaseDirectory=/var/run/clamav
33
46
 
34
47
make_dir "$DataBaseDirectory"
35
48
make_dir $(dirname "$PidFile")
36
49
 
37
 
if [ -f "$PIDFILE" ]; then
38
 
  PID=`pidofproc -p $PIDFILE $DAEMON`
39
 
  RUNNING=$?
40
 
else
41
 
  PID=`pidofproc $DAEMON`
42
 
  RUNNING=$?
43
 
fi
44
 
 
45
 
handle_iface()
46
 
{
47
 
  OPTIND=1
48
 
  if  [ "$1" = "stop" ] && [ "$RUNNING" != 0 ]; then
49
 
    return 1
50
 
  elif [ "$1" = "start" ] && [ "$RUNNING" = 0 ]; then
51
 
    return 1
52
 
  else
53
 
    return 0
54
 
  fi
55
 
  
56
 
  IS_UP=0
57
 
  MATCH=0
58
 
  for inet in $INTERFACE; do
59
 
    route | grep -q "$inet" && IS_UP=`expr "$IS_UP" + 1`
60
 
    [ "$inet" = "$IFACE" ] && MATCH=1
61
 
  done
62
 
  
63
 
  if [ -n "$INTERFACE" ]; then         # Want if-up.d handling
64
 
    if [ -n "$IFACE" ]; then           # Called by if-up.d - for us
65
 
      if [ "$MATCH" = '1' ]; then      # IFACE is ours 
66
 
        if [ "$IS_UP" = '1' ]; then    # and is only one up
67
 
          return 0
68
 
        else                           # Either not up, or others are up
69
 
          return 1
70
 
        fi
71
 
      else                             # IFACE is not ours
72
 
        return 1
73
 
      fi
74
 
    else                               # Not called by if-up.d && $1='(stop|start)'
75
 
      return 1
76
 
    fi
77
 
  else                                 # No if-up.d handling - just return
78
 
    return 0
79
 
  fi
80
 
}
81
 
 
82
 
handle_iface $1 || exit 0
83
 
 
84
50
[ -z "$UpdateLogFile" ] && UpdateLogFile=/var/log/clamav/freshclam.log
85
51
[ -z "$DatabaseDirectory" ] && DatabaseDirectory=/var/lib/clamav/
86
52
[ -n "$DatabaseOwner" ] || DatabaseOwner=clamav
90
56
  su "$DatabaseOwner" -p -s /bin/sh -c "freshclam -l $UpdateLogFile --datadir $DatabaseDirectory"
91
57
  ;;
92
58
  start)
93
 
  OPTIND=1
94
59
  log_daemon_msg "Starting $DESC" "$NAME"
 
60
  if [ ! -f "$PidFile" ]; then
 
61
    # If clamd is run under a different UID than freshclam then we need
 
62
    # to make sure the PidFile can be written or else we won't be able to
 
63
    # kill it.
 
64
    touch $PidFile
 
65
    chown $DatabaseOwner $PidFile
 
66
  fi
95
67
  # If user wants it run from cron, we only accept no-daemon and stop
96
68
  if [ -f /etc/cron.d/clamav-freshclam ]; then
97
69
    log_warning_msg "Not starting $NAME - cron option selected"
98
70
    log_warning_msg "Run the init script with the 'no-daemon' option"
99
71
    log_end_msg 255
 
72
    # this is similar to the daemon already running
100
73
    exit 0
101
74
  fi
102
 
  start-stop-daemon --start -o -c "$DatabaseOwner" --exec $DAEMON -- -d --quiet
 
75
  start-stop-daemon --start --oknodo -c "$DatabaseOwner" --exec $DAEMON --pidfile $PidFile -- -d --quiet --config-file=$FRESHCLAM_CONF_FILE
103
76
  log_end_msg $?
104
77
  ;;
105
78
  stop)
106
 
  OPTIND=1
107
79
  log_daemon_msg "Stopping $DESC" "$NAME"
108
 
  if [ -n "$PID" ]; then
109
 
    kill -15 -"$PID"
110
 
    ret=$?
111
 
    sleep 1
112
 
    if kill -0 "$PID" 2>/dev/null; then
113
 
      ret=$?
114
 
      log_progress_msg "Waiting . "
115
 
      cnt=0
116
 
      while kill -0 "$PID" 2>/dev/null; do
117
 
        ret=$?
118
 
        cnt=`expr "$cnt" + 1`
119
 
        if [ "$cnt" -gt 15 ]; then
120
 
          kill -9 "$PID"
121
 
          ret=$?
122
 
          break
123
 
        fi
124
 
        sleep 2
125
 
        log_progress_msg ". "
126
 
      done
127
 
    fi
128
 
  else
129
 
    killproc -p $PIDFILE $DAEMON
130
 
    ret=$?
131
 
  fi
132
 
  log_end_msg $ret
 
80
  start-stop-daemon --stop --oknodo --name $NAME --pidfile $PidFile --retry TERM/30/KILL/5
 
81
  log_end_msg $?
133
82
  ;;
134
83
  restart|force-reload)
135
84
  $0 stop
136
85
  $0 start
137
86
  ;;
138
87
  reload-log)
139
 
  OPTIND=1
140
88
  log_daemon_msg "Reloading $DESC" "$NAME"
141
 
  if [ "$RUNNING" = 0 ] && [ -n "$PID" ]; then
142
 
    kill -HUP $PID
 
89
  # If user wants it run from cron, we only accept no-daemon and stop
 
90
  if [ -f /etc/cron.d/clamav-freshclam ]; then
 
91
    log_warning_msg "Not reloading log for $NAME - cron option selected"
 
92
    log_end_msg 255
 
93
    # log-reloading is not needed, because freshclam is not run as daemon
 
94
    exit 0
143
95
  fi
 
96
  pkill -HUP -F $PidFile $NAME
144
97
  log_end_msg $?
145
98
  ;;
146
99
  skip)
147
100
  ;;
148
101
  status)
149
 
  status_of_proc "$DAEMON" "$NAME"
150
 
  exit $?
 
102
  start-stop-daemon --status --name $NAME --pidfile $PidFile
 
103
  ret="$?"
 
104
   if [ "$ret" = 0 ]; then
 
105
     log_success_msg "$NAME is running"
 
106
     exit 0
 
107
   else
 
108
     log_failure_msg "$NAME is not running"
 
109
     exit "$ret"
 
110
  fi
151
111
  ;;
152
112
  *)
153
 
  log_failure_msg "Usage: $0 {no-daemon|start|stop|restart|force-reload|reload-log|skip|status}" >&2
154
 
  exit 1
 
113
  log_action_msg "Usage: $0 {no-daemon|start|stop|restart|force-reload|reload-log|skip|status}" >&2
 
114
  # invalid arguments
 
115
  exit 2
155
116
  ;;
156
117
esac
157
118
 
158
119
exit 0
159