17
17
# Description: Clam AntiVirus userspace daemon
20
# The exit status codes should comply with LSB.
21
# https://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html
20
23
PATH=/sbin:/bin:/usr/sbin:/usr/bin
21
24
DAEMON=/usr/sbin/clamd
28
31
SUPERVISORARGS="--name=$NAME --respawn $DAEMON -F $SUPERVISORPIDFILE"
29
32
DATABASEDIR="/var/lib/clamav"
34
# required by Debian policy 9.3.2
31
35
[ -x "$DAEMON" ] || exit 0
32
36
[ -r /etc/default/clamav-daemon ] && . /etc/default/clamav-daemon
40
44
log_failure_msg "Please either dpkg-reconfigure $DESC, or copy the example from"
41
45
log_failure_msg "/usr/share/doc/clamav-base/examples/ to $CLAMAVCONF and run"
42
46
log_failure_msg "'/etc/init.d/clamav-daemon start'"
47
if [ "$1" = "status" ]; then
48
# program or service status is unknown
51
# program is not configured
46
56
slurp_config "$CLAMAVCONF"
48
58
if [ -n "$Example" ]; then
49
59
log_failure_msg "Clamav is not configured."
50
60
log_failure_msg "Please edit $CLAMAVCONF and run '/etc/init.d/clamav-daemon start'"
61
if [ "$1" = "status" ]; then
62
# program or service status is unknown
65
# program is not configured
54
70
if is_true "$Foreground"; then
55
71
if [ ! -x "$SUPERVISOR" ] ; then
56
72
log_failure_msg "Foreground specified, but $SUPERVISORNAME not found"
73
if [ "$1" = "status" ]; then
74
# program or service status is unknown
77
# program is not configured correctly
66
88
make_dir "$DataBaseDirectory"
67
89
make_dir $(dirname "$SUPERVISORPIDFILE")
69
THEPIDFILE="`grep ^PidFile $CLAMAVCONF | awk '{print $2}'`"
70
[ -n "$THEPIDFILE" ] || THEPIDFILE='/var/run/clamav/clamd.pid'
91
if [ -z "$RUN_SUPERVISED" ]; then
96
THEPIDFILE="$SUPERVISORPIDFILE"
97
THEDAEMON="$SUPERVISORNAME"
101
if [ -z "$THEPIDFILE" ]
103
log_failure_msg "$NAME: Can not continue with PidFile not set"
104
if [ "$1" = "status" ]; then
105
# program or service status is unknown
108
# program is not configured correctly
71
113
make_dir $(dirname "$THEPIDFILE")
72
114
chown $User $(dirname "$THEPIDFILE")
74
if [ -f "$THEPIDFILE" ]; then
75
CLAMDPID=`pidofproc -p $THEPIDFILE $DAEMON`
78
CLAMDPID=`pidofproc $DAEMON`
82
if [ -z "$RUN_SUPERVISED" ]; then
85
[ -e "$SUPERVISORPIDFILE" ] && PID=`cat $SUPERVISORPIDFILE`
88
[ "$PID" = '1' ] && unset PID
93
119
# Check for database existance (start will fail if it's missing)
94
120
for db in main daily; do
95
121
if [ ! -e "$DATABASEDIR"/"$db".cvd ] && [ ! -d "$DATABASEDIR"/"$db".inc ] && [ ! -e "$DATABASEDIR"/"$db".cld ]; then
96
122
log_failure_msg "Clamav signatures not found in $DATABASEDIR"
97
123
log_failure_msg "Please retrieve them using freshclam"
98
124
log_failure_msg "Then run '/etc/init.d/clamav-daemon start'"
125
# this is expected on a fresh installation
102
129
if [ -z "$RUN_SUPERVISED" ] ; then
103
130
log_daemon_msg "Starting $DESC" "$NAME "
104
start-stop-daemon --start -o -c $User --exec $DAEMON
131
start-stop-daemon --start --oknodo -c $User --exec $DAEMON --pidfile $THEPIDFILE -- -c $CLAMAVCONF
107
134
log_daemon_msg "Starting $DESC" "$NAME (supervised) "
114
141
log_daemon_msg "Stopping $DESC" "$NAME"
116
if [ -n "$PID" ]; then
120
if kill -0 "$PID" 2>/dev/null; then
122
log_progress_msg "Waiting . "
124
while kill -0 "$PID" 2>/dev/null; do
126
cnt=`expr "$cnt" + 1`
127
if [ "$cnt" -gt 15 ]; then
132
log_progress_msg ". "
136
if [ -z "$RUN_SUPERVISED" ] ; then
137
killproc -p $THEPIDFILE
140
killproc -p $SUPERVISORPIDFILE
144
if [ -n "$ret" ]; then
142
start-stop-daemon --stop --oknodo --name $THEDAEMON --pidfile $THEPIDFILE --retry TERM/30/KILL/5
151
status_of_proc "$DAEMON" "$NAME"
146
start-stop-daemon --status --name $THEDAEMON --pidfile $THEPIDFILE
147
# start-stop-daemon returns LSB compliant exit status codes
149
if [ "$ret" = 0 ]; then
150
log_success_msg "$NAME is running"
152
log_failure_msg "$NAME is not running"
154
156
restart|force-reload)
160
log_daemon_msg "Reloading database for $DESC" "$NAME"
161
if [ "$RUNNING" = 0 ] && [ -n "$CLAMDPID" ]; then
161
if [ "$RELOAD" = "1" ]; then
162
log_daemon_msg "Reloading database for $DESC" "$NAME"
163
pkill -USR2 -F $THEPIDFILE $THEDAEMON 2>/dev/null
166
log_failure_msg "reload-database does not work in supervised mode."
167
# unimplemented feature
168
log_daemon_msg "Reloading log file for $DESC" "$NAME"
169
if [ "$RUNNING" = 0 ] && [ -n "$CLAMDPID" ]; then
172
if [ "$RELOAD" = "1" ]; then
173
log_daemon_msg "Reloading log file for $DESC" "$NAME"
174
pkill -HUP -F $THEPIDFILE $THEDAEMON 2>/dev/null
176
log_failure_msg "reload-log does not work in supervised mode."
177
# unimplemented feature
175
log_failure_msg "Usage: $0 {start|stop|restart|force-reload|reload-log|reload-database|status}" >&2
183
log_action_msg "Usage: $0 {start|stop|restart|force-reload|reload-log|reload-database|status}" >&2