#!/sbin/runscript # Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/app-antivirus/clamav/files/clamd.rc,v 1.15 2007/04/13 20:56:34 ticho Exp $ opts="logfix" depend() { use net provide antivirus } start() { local clamd_socket=`awk '$1 == "LocalSocket" { print $2 }' /etc/clamd.conf` logfix if [ "${START_CLAMD}" = "yes" ]; then if [ -S "${clamd_socket:-/tmp/clamd}" ]; then rm -f ${clamd_socket:-/tmp/clamd} fi ebegin "Starting clamd" start-stop-daemon --start --quiet \ --exec /usr/sbin/clamd eend $? "Failed to start clamd" fi if [ "${START_FRESHCLAM}" = "yes" ]; then ebegin "Starting freshclam" start-stop-daemon --start --quiet \ --exec /usr/bin/freshclam -- -d retcode=$? if [ ${retcode} = 1 ]; then eend 0 einfo "Virus databases are already up to date." else eend ${retcode} "Failed to start freshclam" fi fi if [ "${START_MILTER}" = "yes" ]; then if [ -S "${MILTER_SOCKET}" ]; then rm -f ${MILTER_SOCKET} fi local milter_ext=no local milter_svr=no args=`getopt -q --options "es" --longoptions "external,server" -- $MILTER_OPTS` for arg in $args; do case "$arg" in -e | --external) milter_ext=yes; shift;; -s | --server) milter_svr=yes; shift;; --) shift; break;; esac done if [[ $milter_ext == yes && $milter_svr == no ]]; then local clamd_socket_wait_count=0 local clamd_socket_wait_max=10 local clamd_socket_wait_result=-1 ebegin "Waiting for clamd to create ${clamd_socket}" while (( clamd_socket_wait < clamd_socket_wait_max )); do if [ -S "${clamd_socket:-/tmp/clamd}" ]; then clamd_socket_wait_result=0 break else echo -n " ." let clamd_socket_wait++ sleep 1 fi done echo eend $clamd_socket_wait_result "Timeout waiting for ${clamd_socket}" fi ebegin "Starting clamav-milter" start-stop-daemon --start --quiet \ --exec /usr/sbin/clamav-milter -- ${MILTER_OPTS} ${MILTER_SOCKET} eend $? "Failed to start clamav-milter" fi } stop() { if [ "${START_CLAMD}" = "yes" ]; then ebegin "Stopping clamd" start-stop-daemon --stop --quiet --name clamd eend $? "Failed to stop clamd" fi if [ "${START_FRESHCLAM}" = "yes" ]; then ebegin "Stopping freshclam" start-stop-daemon --stop --quiet --name freshclam eend $? "Failed to stop freshclam" fi if [ "${START_MILTER}" = "yes" ]; then ebegin "Stopping clamav-milter" start-stop-daemon --stop --quiet --name clamav-milter eend $? "Failed to stop clamav-milter" fi } logfix() { if [ "${START_CLAMD}" = "yes" ]; then # fix clamd log permissions # (might be clobbered by logrotate or something) local logfile=`awk '$1 == "LogFile" { print $2 }' /etc/clamd.conf` local clamav_user=`awk '$1 == "User" { print $2 }' /etc/clamd.conf` if [ -n "${logfile}" ] && [ -n "${clamav_user}" ]; then if [ ! -f "${logfile}" ]; then touch ${logfile} fi chown ${clamav_user} ${logfile} chmod 640 ${logfile} fi fi if [ "${START_FRESHCLAM}" = "yes" ]; then # fix freshclam log permissions # (might be clobbered by logrotate or something) logfile=`awk '$1 == "UpdateLogFile" { print $2 }' /etc/freshclam.conf` local freshclam_user=`awk '$1 == "DatabaseOwner" { print $2 }' /etc/freshclam.conf` if [ -n "${logfile}" -a -n "${clamav_user}" ]; then if [ ! -f "${logfile}" ]; then touch ${logfile} fi chown ${freshclam_user} ${logfile} chmod 640 ${logfile} fi fi }