#!/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>
#
# iprinit
#
# System startup script for the ipr init facility
#
### BEGIN INIT INFO
# Provides: iprinit
# Required-Start:    $local_fs
# Should-Start:      $remote_fs $syslog
# Required-Stop:     $local_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start the ipr init daemon
# Description:       Start the ipr initialization daemon
### END INIT INFO
#
# chkconfig: 2345 20 80
# description: Runs the IBM Power RAID adapter initialization daemon
# processname: iprinit
# pidfile: /var/run/iprinit.pid
#

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

RETVAL=0

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

start() {
    echo -n "Starting iprinit: "
    if [ ! -d /sys/class/scsi_generic ] ; then
        modprobe sg
    fi
    daemon $iprinit --daemon

    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch $lockfile && /sbin/pidof $iprinit > $pidfile
    return $RETVAL
}

stop() {
    echo -n "Stopping iprinit: "
    killproc $iprinit -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
        ;;
    condrestart)
        if [ -f $lockfile ]; then
            stop ; start
            RETVAL=$?
        fi
        ;;
    status)
        status $iprinit
        RETVAL=$?
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=3
        ;;
esac

