#!/bin/sh
#
# smartd:	S.M.A.R.T. Daemon
#
# chkconfig:	345 32 68
#
# description:	S.M.A.R.T. Daemon
#
# $Id$

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

# Get service config - may override defaults
[ -f /etc/sysconfig/smartd ] && . /etc/sysconfig/smartd

start() {
	if [ -f /var/lock/subsys/smartd ]; then
		msg_already_running "S.M.A.R.T. Daemon"
		return
	fi

	msg_starting "S.M.A.R.T. Daemon"
	daemon /usr/sbin/smartd </dev/null
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/smartd
}

stop() {
	if [ ! -f /var/lock/subsys/smartd ]; then
		msg_not_running "S.M.A.R.T. Daemon"
		return
	fi

	msg_stopping "S.M.A.R.T. Daemon"
	killproc smartd
	rm -f /var/lock/subsys/smartd
}

condrestart() {
	if [ ! -f /var/lock/subsys/smartd ]; then
		msg_not_running "S.M.A.R.T. Daemon"
		RETVAL=$1
		return
	fi

	stop
	start
}

reload() {
	if [ ! -f /var/lock/subsys/smartd ]; then
		msg_not_running "S.M.A.R.T. Daemon"
		RETVAL=7
		return
	fi

	msg_reloading "S.M.A.R.T. Daemon"
	killproc smartd -HUP
	RETVAL=$?
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  reload|force-reload)
	reload
	;;
  status)
	status smartd
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac
exit $RETVAL
