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