~ubuntu-branches/ubuntu/utopic/clamav/utopic-updates

« 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-04-25 15:01:05 UTC
  • mfrom: (0.35.41 sid)
  • Revision ID: package-import@ubuntu.com-20140425150105-n4wqi1w9yjgktgfb
Tags: 0.98.1+dfsg-5ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - Drop build-dep on electric-fence (in Universe)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
CLAMAV_CONF_FILE=/etc/clamav/clamd.conf
21
21
FRESHCLAM_CONF_FILE=/etc/clamav/freshclam.conf
22
 
PIDFILE=/var/run/clamav/freshclam.pid
23
22
[ -f /var/lib/clamav/interface ] && INTERFACE=`cat /var/lib/clamav/interface`
24
23
 
25
24
#COMMON-FUNCTIONS#
28
27
 
29
28
slurp_config "$FRESHCLAM_CONF_FILE"
30
29
 
31
 
[ -n "$PidFile" ] && PIDFILE="$PidFile"
 
30
if [ -z "$PidFile" ]
 
31
then
 
32
        log_failure_msg "$NAME: Can not continue with PidFile not set"
 
33
        exit 1
 
34
fi
32
35
[ -n "$DataBaseDirectory" ] || DataBaseDirectory=/var/run/clamav
33
36
 
34
37
make_dir "$DataBaseDirectory"
35
38
make_dir $(dirname "$PidFile")
36
39
 
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
40
handle_iface()
46
41
{
47
 
  OPTIND=1
 
42
  pkill -0 -F $PidFile $NAME 2>/dev/null
 
43
  RUNNING=$?
 
44
 
48
45
  if  [ "$1" = "stop" ] && [ "$RUNNING" != 0 ]; then
49
46
    return 1
50
47
  elif [ "$1" = "start" ] && [ "$RUNNING" = 0 ]; then
85
82
[ -z "$DatabaseDirectory" ] && DatabaseDirectory=/var/lib/clamav/
86
83
[ -n "$DatabaseOwner" ] || DatabaseOwner=clamav
87
84
 
 
85
if [ ! -f "$PidFile" ]
 
86
then
 
87
        # If clamd is run under a different UID than freshclam then we need
 
88
        # to make sure the PidFile can be written or else we won't be able to
 
89
        # kill it.
 
90
        touch $PidFile
 
91
        chown $DatabaseOwner $PidFile
 
92
fi
 
93
 
88
94
case "$1" in
89
95
  no-daemon)
90
96
  su "$DatabaseOwner" -p -s /bin/sh -c "freshclam -l $UpdateLogFile --datadir $DatabaseDirectory"
91
97
  ;;
92
98
  start)
93
 
  OPTIND=1
94
99
  log_daemon_msg "Starting $DESC" "$NAME"
95
100
  # If user wants it run from cron, we only accept no-daemon and stop
96
101
  if [ -f /etc/cron.d/clamav-freshclam ]; then
99
104
    log_end_msg 255
100
105
    exit 0
101
106
  fi
102
 
  start-stop-daemon --start -o -c "$DatabaseOwner" --exec $DAEMON -- -d --quiet
 
107
  start-stop-daemon --start --oknodo -c "$DatabaseOwner" --exec $DAEMON --pidfile $PidFile -- -d --quiet
103
108
  log_end_msg $?
104
109
  ;;
105
110
  stop)
106
 
  OPTIND=1
107
111
  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
 
112
  start-stop-daemon --stop --oknodo --name $NAME --pidfile $PidFile --retry TERM/30/KILL/5
 
113
  log_end_msg $?
133
114
  ;;
134
115
  restart|force-reload)
135
116
  $0 stop
136
117
  $0 start
137
118
  ;;
138
119
  reload-log)
139
 
  OPTIND=1
140
120
  log_daemon_msg "Reloading $DESC" "$NAME"
141
 
  if [ "$RUNNING" = 0 ] && [ -n "$PID" ]; then
142
 
    kill -HUP $PID
143
 
  fi
 
121
  pkill -HUP -F $PidFile $NAME
144
122
  log_end_msg $?
145
123
  ;;
146
124
  skip)
147
125
  ;;
148
126
  status)
149
 
  status_of_proc "$DAEMON" "$NAME"
150
 
  exit $?
 
127
  start-stop-daemon --status --name $NAME --pidfile $PidFile
 
128
   if [ "$?" = 0 ]; then
 
129
     log_success_msg "$NAME is running"
 
130
     exit 0
 
131
   else
 
132
     log_failure_msg "$NAME is not running"
 
133
     exit 1
 
134
  fi
151
135
  ;;
152
136
  *)
153
 
  log_failure_msg "Usage: $0 {no-daemon|start|stop|restart|force-reload|reload-log|skip|status}" >&2
 
137
  log_action_msg "Usage: $0 {no-daemon|start|stop|restart|force-reload|reload-log|skip|status}" >&2
154
138
  exit 1
155
139
  ;;
156
140
esac
157
141
 
158
142
exit 0
159