#! /bin/bash
#
# smartd         Start/Stop the S.M.A.R.T. monitoring daemon.
#
# chkconfig: 2345 86 14
# description: smartd scan for all devices that support SMART periodically \
#              poll them for errors. When an error occurs it sends log \
#              information to the SYSLOG facility.
# processname: smartd
# pidfile: /var/run/smartd.pid

# Source function library.
. /etc/init.d/functions

if [ -f /etc/sysconfig/smartdevices ] ; then
	. /etc/sysconfig/smartdevices
fi

RETVAL=0

# See how we were called.
  
start() {
	if [ ! -z "$SMARTDEVICES" ]; then 
		for DEVICE in $SMARTDEVICES; do
			smartctl -e $DEVICE
		done
	fi
	echo -n "Starting smartd: "
	daemon smartd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/smartd
	return $RETVAL
}

stop() {
	echo -n $"Stopping smartd: "
	killproc smartd
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/smartd
	return $RETVAL
}	

rhstatus() {
	status smartd
}	

restart() {
  	stop
	start
}	

reload() {
	stop
	start
}	

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

exit $?
