#!/bin/sh
# clamd         This shell script takes care of starting and stopping
#               clamd.
#
# chkconfig: - 61 39
# description: clamd is an antivirus daemon
# processname: clamd
# config: /etc/clamd.conf
# pidfile: /var/run/clamd/clamd.pid

# Source function library.
. /usr/local/etc/rc.d/functions

[ -x /usr/sbin/clamd ] || exit 0

RETVAL=0

LOCK_FILE=/var/spool/lock/clamd

start() {
        echo -n "Starting clamd: "
        daemon /usr/sbin/clamd
        RETVAL=$?
        if [ $RETVAL -eq 0 ] && touch $LOCK_FILE
	then
		echo -e "\t\t[ OK ]";
	else
		echo -e "\t\t[ FAILED ]";
	fi
        return $RETVAL
}

stop() {
        echo -n "Shutting down clamd: "
        killall clamd 2> /dev/null
        RETVAL=$?
        if [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
	then
		echo -e "\t\t[ OK ]";
	else
		echo -e "\t\t[ FAILED ]";
	fi
        return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status clamd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f $LOCK_FILE ]; then
          stop
          start
          RETVAL=$?
        fi
        ;;
  reload)
        echo -n "Re-reading clamd configuration: "
        killall -HUP clamd 2> /dev/null
        RETVAL=$?
	if [ $RETVAL = 0 ]
	then
		echo -e "\t[ OK ]";
	else
		echo -e "\t[ FAILED ]";
	fi
        ;;
  *)
        echo "Usage: clamd {start|stop|restart|reload|condrestart|status}"
        exit 1
esac

exit $RETVAL
