#! /bin/sh

# smartmontools init file for smartd
# Copyright (C) 2002-8 Bruce Allen <smartmontools-support@lists.sourceforge.net>
# $Id: smartd.initd.in 4120 2015-08-27 16:12:21Z samm2 $

# description: Self Monitoring and Reporting Technology (SMART) Daemon
# processname: smartd 
# Description:                Start S.M.A.R.T. disk and tape monitor.

# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2, or (at your option) any later
# version. 
# You should have received a copy of the GNU General Public License (for
# example COPYING); if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# This code was originally developed as a Senior Thesis by Michael Cornwell
# at the Concurrent Systems Laboratory (now part of the Storage Systems
# Research Center), Jack Baskin School of Engineering, University of
# California, Santa Cruz. http://ssrc.soe.ucsc.edu/.

# Modified for use in SMLinux

# Uncomment the line below to pass options to smartd on startup. 
# Note that distribution specific configuration files like
# /etc/{default,sysconfig}/smartmontools might override these
#smartd_opts="--interval=1800"

SMARTD_BIN=/bin/smartd

[ -r /etc/sysconfig/smartmontools ] && . /etc/sysconfig/smartmontools

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
