12
12
# Description: Clam AntiVirus virus database updater
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
15
18
DAEMON=/usr/bin/freshclam
17
20
DESC="ClamAV virus database updater"
22
# required by Debian policy 9.3.2
18
23
[ -x $DAEMON ] || exit 0
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`
29
32
slurp_config "$FRESHCLAM_CONF_FILE"
31
[ -n "$PidFile" ] && PIDFILE="$PidFile"
36
log_failure_msg "$NAME: Can not continue with PidFile not set"
37
if [ "$1" = "status" ]; then
38
# program or service status is unknown
41
# program is not configured correctly
32
45
[ -n "$DataBaseDirectory" ] || DataBaseDirectory=/var/run/clamav
34
47
make_dir "$DataBaseDirectory"
35
48
make_dir $(dirname "$PidFile")
37
if [ -f "$PIDFILE" ]; then
38
PID=`pidofproc -p $PIDFILE $DAEMON`
41
PID=`pidofproc $DAEMON`
48
if [ "$1" = "stop" ] && [ "$RUNNING" != 0 ]; then
50
elif [ "$1" = "start" ] && [ "$RUNNING" = 0 ]; then
58
for inet in $INTERFACE; do
59
route | grep -q "$inet" && IS_UP=`expr "$IS_UP" + 1`
60
[ "$inet" = "$IFACE" ] && MATCH=1
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
68
else # Either not up, or others are up
71
else # IFACE is not ours
74
else # Not called by if-up.d && $1='(stop|start)'
77
else # No if-up.d handling - just return
82
handle_iface $1 || exit 0
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"
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
65
chown $DatabaseOwner $PidFile
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"
72
# this is similar to the daemon already running
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
107
79
log_daemon_msg "Stopping $DESC" "$NAME"
108
if [ -n "$PID" ]; then
112
if kill -0 "$PID" 2>/dev/null; then
114
log_progress_msg "Waiting . "
116
while kill -0 "$PID" 2>/dev/null; do
118
cnt=`expr "$cnt" + 1`
119
if [ "$cnt" -gt 15 ]; then
125
log_progress_msg ". "
129
killproc -p $PIDFILE $DAEMON
80
start-stop-daemon --stop --oknodo --name $NAME --pidfile $PidFile --retry TERM/30/KILL/5
134
83
restart|force-reload)
140
88
log_daemon_msg "Reloading $DESC" "$NAME"
141
if [ "$RUNNING" = 0 ] && [ -n "$PID" ]; then
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"
93
# log-reloading is not needed, because freshclam is not run as daemon
96
pkill -HUP -F $PidFile $NAME
149
status_of_proc "$DAEMON" "$NAME"
102
start-stop-daemon --status --name $NAME --pidfile $PidFile
104
if [ "$ret" = 0 ]; then
105
log_success_msg "$NAME is running"
108
log_failure_msg "$NAME is not running"
153
log_failure_msg "Usage: $0 {no-daemon|start|stop|restart|force-reload|reload-log|skip|status}" >&2
113
log_action_msg "Usage: $0 {no-daemon|start|stop|restart|force-reload|reload-log|skip|status}" >&2