#!/bin/sh
#
# clamd		Script to start/stop clamd.
#
# chkconfig:	- 61 39
# description:	clamd is an antivirus daemon.
#
# processname: clamd
# config: /etc/clamd.conf
# pidfile: /var/run/clamav/clamd.pid

# Source function library
SYSTEMCTL_SKIP_REDIRECT=1

. /etc/rc.d/init.d/functions

# Get network config
. /etc/sysconfig/network

test -f /etc/clamd.conf || exit 0

# Process config
CLAMD_USER='clamav'
CLAMD_GROUP='clamav'
PIDDIR='/var/run/clamav'

RETVAL=0

start() {
    # Make sure the default pidfile directory exists
    if [ ! -d $PIDDIR ]; then
        install -d -m 0755 -o $CLAMD_USER -g $CLAMD_GROUP $PIDDIR
    fi
	echo -n $"Starting Clam AV daemon: "
	daemon /usr/sbin/clamd 
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/clamd		
	return $RETVAL
}

stop() {
	echo -n $"Stopping Clam AV daemon: "
	killproc clamd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/run/clamav/clamd.pid /var/lock/subsys/clamd
	return $RETVAL
}

restart() {
	stop
	start
}

reload() {
        echo -n $"Reloading DB: "
        killproc clamd -USR2
        RETVAL=$?
        echo
        return $RETVAL
}


case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status clamd
	;;
  restart)
	restart
	;;
  condrestart)
	[ -f /var/lock/subsys/clamd ] && restart || :
	;;
  reload)
	reload
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
	exit 1
esac

exit $?

