#! /bin/sh
# Fatdog smartd init script
# Hacked from smartmontool's smartd.sample startup script
# We base ours from slackware's version of init script.
#
# Description: Self Monitoring and Reporting Technology (SMART) Daemon
#
# smartmontools init file for smartd
# Copyright (C) 2002-8 Bruce Allen <smartmontools-support@lists.sourceforge.net>
# $Id: smartd.initd.in 3727 2012-12-13 17:23:06Z samm2 $
#

SMARTD_BIN=/usr/sbin/smartd
CONFFILE=/etc/smartd-daemon.conf 

# should contain smartd_opts, e.g. smartd_opts="--interval=1800"
[ -r $CONFFILE ] && . $CONFFILE

RETVAL=0
case "$1" in
start)
	echo -n "Starting smartd: "
	$SMARTD_BIN $smartd_opts
	RETVAL=$?
	echo
	;;
stop)
	echo -n "Shutting down smartd: "
	killall $SMARTD_BIN
	RETVAL=$?
	echo
	;;
restart)
	$0 stop
	sleep 1
	$0 start
	RETVAL=$?
	;;
try-restart)
	if pidof $SMARTD_BIN >/dev/null; then
	$0 restart
	RETVAL=$?
	fi
	;;
force-reload)
	$0 reload || $0 restart
	RETVAL=$?
	;;
reload)
	echo -n "Reloading smartd configuration: "
	killall -s HUP $SMARTD_BIN
	RETVAL=$?
	echo
	;;
report)
	echo -n "Checking SMART devices now: "
	killall -s USR1 $SMARTD_BIN
	RETVAL=$?
	echo
	;;
status)
	if pidof $SMARTD_BIN >/dev/null; then
	echo "$SMARTD_BIN is running."
	else
	echo "$SMARTD_BIN is not running."
	RETVAL=1
	fi
	;;
*)
	echo "Usage: $0 {start|stop|restart|try-restart|force-reload|reload|report|status}"
	RETVAL=1
esac
exit $RETVAL
