1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-22 18:55:29 +03:00
aports/community/clamav/clamd.initd
2021-04-25 10:33:36 +00:00

85 lines
2 KiB
Text
Executable file

#!/sbin/openrc-run
NAME=clamd
CONF=/etc/clamav/clamd.conf
pidfile=/run/clamav/clamd.pid
command=/usr/sbin/clamd
extra_started_commands="reload"
extra_commands="logfix"
required_files=$CONF
depend() {
need net
after firewall
provide antivirus
}
start_pre() {
# fix clamd run permissions
local pid=`awk '$1 == "PidFile" { print $2 }' $CONF`
[ "x$pid" != "x" ] && pidfile=$pid
local socket=`awk '$1 == "LocalSocket" { print $2 }' $CONF`
local socketdir=${socket%/*}
local clamav_user=`awk '$1 == "User" { print $2 }' $CONF`
checkpath --directory --owner ${clamav_user:-clamav} \
--mode 750 ${pidfile%/*}
checkpath --directory --owner ${clamav_user:-clamav} \
--mode 755 ${socketdir:-/run/clamav}
}
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 timeout=${FRESHCLAM_TIMEOUT:-120}
local cvd="${dbdir:-/var/lib/clamav}"/main.cvd
local cld="${dbdir:-/var/lib/clamav}"/main.cld
if ! [ -e "$cld" ]; then
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
fi
ebegin "Starting ${NAME}"
start-stop-daemon --start --quiet \
--nicelevel ${CLAMD_NICELEVEL:-0} \
--exec $command
eend $? "Failed to start ${NAME}"
}
reload() {
ebegin "Reloading ${SVCNAME}"
start-stop-daemon --signal HUP --pidfile $pidfile --name $SVCNAME
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
checkpath -Fm 0640 -o ${clamav_user} ${logfile}
else
chmod 640 ${logfile}
chown ${clamav_user} ${logfile}
fi
fi
}