#! /bin/sh
# chkconfig: 2345 40 40
# smartmontools init file for smartd
#
# description: Self Monitoring and Reporting Technology (SMART) Daemon
#
# processname: smartd 
#
# $Id: smartd.initd.in,v 1.3 2003/10/12 21:02:17 arvoreen Exp $
#
# Copyright (C) 2002-3 Bruce Allen 
# 
# 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., 675
# Mass Ave, Cambridge, MA 02139, 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/.
#

report_unsupported () {
    echo "Currently the smartmontools package has no init script for"
    echo "the $1 Linux distribution. If you can provide one or this"
    echo "one works only removing some ifdefs, please contact"
    echo "smartmontools-support@lists.sourceforge.net."
    exit 1
}

# Red Hat
if [ -f /etc/redhat-release ] ; then

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

    case "$1" in
	start)
	    echo -n "Starting smartd: "
	    daemon /usr/sbin/smartd
	    touch /var/lock/subsys/smartd
	    echo
	    ;;
	stop)
	    echo -n "Shutting down smartd: "
	    killproc smartd
	    rm -f /var/lock/subsys/smartd
	    echo
	    ;;
	restart)
	    $0 stop
	    $0 start
	    ;;
	status)
	    status smartd
	    ;;
	*)
	    echo "Usage: smartd {start|stop|restart|status}"
	    exit 1
    esac
    
    exit 0

# Slackware
elif [ -f /etc/slackware-release ] ; then

    case "$1" in
	start)
	    echo -n "Starting smartd: "
	    smartd
	    echo
	    ;;
	stop)
	    echo -n "Shutting down smartd: "
	    killall smartd
	    echo
	    ;;
	restart)
	    $0 stop
	    sleep 1
	    $0 start
	    ;;
	*)
	    echo "Usage: smartd {start|stop|restart}"
	    exit 1
    esac
    
    exit 0

# Add other distributions HERE, using elif...
elif [ -f /etc/environment.corel ] ; then
    report_unsupported "Corel"
elif [ -f /etc/debian_version ] ; then
    report_unsupported "Debian"
elif [ -f /etc/gentoo-release ] ; then
    report_unsupported "Gentoo"
elif [ -f /etc/mandrake-release ] ; then
    report_unsupported "Mandrake"
elif [ -f /etc/SuSE-release ] ; then
    report_unsupported "SuSE"
elif [ -f /etc/turbolinux-release ] ; then
    report_unsupported "Turbolinux"
elif uname -a | grep -q FreeBSD ; then

PID_FILE=/var/run/smartd.pid

    case "$1" in
	start)
	    smartd -p $PID_FILE
	    echo -n "smartd "
	    ;;
	stop)
	    kill `cat $PID_FILE`
	    echo -n "smartd "
	    ;;
	restart)
	    $0 stop
	    sleep 1
	    $0 start
	    ;;
	*)
	    echo "Usage: smartd {start|stop|restart}"
	    exit 1
    esac
    
    exit 0

else
    report_unsupported "Unknown"
fi