aports/main/clamav/clamd.initd
Natanael Copa 4cd38832fb main/clamav: separate clamav-db and freshclam
Having a big static db in a package is not a good idea for /var on disk
installs. We ship the db and freshclam in separate packages.

also clean up the install and init.d scripts while here.

fixes #1047
2012-04-30 15:13:30 +00:00

78 lines
1.6 KiB
Plaintext
Executable File

#!/sbin/runscript
extra_started_commands="reload"
extra_commands="logfix"
NAME=clamd
CONF=/etc/clamav/clamd.conf
depend() {
need net
after firewall
provide antivirus
}
start() {
local clamd_socket=$(awk '$1 == "LocalSocket" { print $2 }' $CONF)
logfix
if [ -S "${clamd_socket:=/tmp/clamd}" ]; then
rm -f ${clamd_socket}
fi
local dbdir=$(awk '$1 == "DatabaseDirectory" { print $2 }' $CONF)
local timout=${FRESHCLAM_TIMEOUT:-120}
local cvd="${dbdir:-/var/lib/clamav}"/main.cvd
if ! [ -e "$cvd" ]; then
ebegin "Waiting for clamav database download"
while ! [ -e "$cvd" ]; do
timeout=$(( $timeout - 1 ))
if [ $timeout -eq 0 ]; then
eend 1 "Timed out"
return 1
fi
sleep 1
done
eend 0
fi
ebegin "Starting ${NAME}"
start-stop-daemon --start --quiet \
--nicelevel ${CLAMD_NICELEVEL:-0} \
--exec /usr/sbin/clamd
eend $? "Failed to start ${NAME}"
}
stop() {
ebegin "Stopping ${NAME}"
start-stop-daemon --stop --quiet --exec /usr/sbin/clamd
eend $?
}
reload() {
ebegin "Reloading ${NAME}"
if ! service_started "${NAME}" ; then
eend 1 "${NAME} is not started"
return 1
fi
start-stop-daemon --stop --signal HUP \
--exec /usr/sbin/clamd
eend $?
}
logfix() {
# fix clamd log permissions
# (might be clobbered by logrotate or something)
local logfile=`awk '$1 == "LogFile" { print $2 }' $CONF`
local clamav_user=`awk '$1 == "User" { print $2 }' $CONF`
if [ -n "${logfile}" ] && [ -n "${clamav_user}" ]; then
if [ ! -f "${logfile}" ]; then
touch ${logfile}
fi
chown ${clamav_user} ${logfile}
chmod 640 ${logfile}
fi
}