#! /bin/bash # # description: clamd is a standard UNIX program that scans for Viruses. mkdir -p /var/lock/subsys mkdir -p /run/clamav chown clamav:clamav /run/clamav ppid="/run/clamav/clamd.pid" prog="/usr/sbin/clamd" sprog="/usr/sbin/clamsmtpd" sconf="/etc/clamsmtpd.conf" mpid="/run/clamav/clamav-milter.pid" mprog="/usr/sbin/clamav-milter" mconf="/etc/clamav/clamav-milter.conf" start() { echo -n "Starting ClamAV: " # Make sure these excist, /var/run might be on a tmpfs /usr/bin/mkdir -p /run/clamav /usr/bin/chown clamav:clamav /run/clamav if [ ! -f $ppid ]; then $prog >/dev/null if [ $? -eq 0 ]; then echo -n "$prog " # Wait until clamd is fully running. while [ ! -f $ppid ] do sleep 1 done if [ -x $mprog -a -f $mconf ]; then $mprog >/dev/null echo -n "$mprog " fi if [ -x $sprog -a -f $sconf ]; then $sprog -f $sconf echo -n "$sprog " fi fi fi echo touch /var/lock/subsys/clamd } stop() { echo -n "Stopping ClamAV: " if [ -f $ppid ]; then # clamsmtp if [ -x $sprog -a -f $sconf ]; then SPID=$( /sbin/pidof $sprog ) if [ ! -z "$SPID" ]; then /bin/kill $SPID echo -n "$sprog " fi fi # clamav-milter if [ -x $mprog -a -f $mconf ]; then /bin/kill $( /usr/bin/cat $mpid ) echo -n "$mprog " fi /bin/kill $( /usr/bin/cat $ppid ) echo -n "$prog " # while [ -f $ppid ] # do # sleep 1 # done fi rm -f /var/lock/subsys/clamd } restart() { stop while [ -f $ppid ]; do sleep 1 echo -n '.' done echo start } reload() { echo -n "Reloading clam daemon configuration: " if [ -f $ppid ]; then /bin/kill -HUP $( /usr/bin/cat $ppid ) fi } case "$1" in start) start ;; stop) stop echo ;; restart) restart ;; reload) reload ;; *) echo $"Usage: $0 {start|stop|reload|restart}" esac exit 0