#!/bin/sh
# Copyright (C) 2004 International Business Machines Corporation and others.
# All Rights Reserved. This program and the accompanying
# materials are made available under the terms of the
# Common Public License v1.0 which accompanies this distribution.
#
# Author: Brian King <brking@us.ibm.com>
#
# iprdump
#
# System startup script for the ipr dump facility
#
### BEGIN INIT INFO
# Provides: iprdump
# Required-Start:    $local_fs iprinit
# Should-Start:      $remote_fs $syslog
# Required-Stop:     $local_fs $syslog iprinit
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the ipr dump daemon
# Description:       Start the ipr dump daemon
### END INIT INFO
#
# chkconfig: 2345 20 80
# description: Runs the IBM Power RAID adapter dump daemon
# processname: iprdump
# pidfile: /var/run/iprdump.pid
#

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

RETVAL=0

prog=iprdump
iprdump=/sbin/iprdump
lockfile=/var/lock/subsys/iprdump
pidfile=/var/run/iprdump.pid

start() {
    echo -n "Starting ipr dump daemon"
    if [ ! -d /sys/class/scsi_generic ] ; then
        modprobe sg
    fi
    
    daemon $iprdump
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch $lockfile && /sbin/pidof $iprdump > $pidfile
    return $RETVAL
}

stop() {
    echo -n "Stopping iprdump: "
    killproc $iprdump -TERM
    RETVAL=$?
    rm -f $lockfile $pidfile
    [ $RETVAL = 0 ] || return $RETVAL
}

case "$1" in
    start)
	start
	RETVAL=$?
	;;
    stop)
	stop
	RETVAL=$?
	;;
    restart|force-reload)
	stop; start
	RETVAL=$?
	;;
    try-restart|reload|configtest)
	RETVAL=3
	reload
	;;
    condrestart)
	if [ -f $lockfile ]; then
            stop ; start
            RETVAL=$?
        fi
        ;;

    status)
	status $iprdump
	RETVAL=$?
	;;
    *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=3
	;;
esac
