#!/bin/bash
#
# opensm       This starts and stops the OpenIB Subnet Manager.
#
# chkconfig: - 12 88
# description: The opensm daemon is needed on at least one machine in \
#	       an Infiniband subnet to manage the link IDs and routing \
#              information that Infiniband host controllers use to access \
#              other host controllers or switches in the subnet fabric.
#
# processname: /usr/sbin/opensm
# pidfile: /var/run/opensm.pid

PATH=/sbin:/bin:/usr/bin:/usr/sbin

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

OPENSM_OPTS="-r -maxsmps 0"

# Check that we are root ... so non-root users stop here
[ `id -u` = 0 ] || exit 1

RETVAL=0

prog="opensm"

start(){
    echo -n $"Starting $prog: "

    ($prog $OPENSM_OPTS) &>/var/log/opensm.log </dev/null &
    RETVAL=$?
    DAEMON_PID=$!
    if [ "$RETVAL" -eq 0 ]; then
	echo $DAEMON_PID > /var/run/opensm.pid
	touch /var/lock/subsys/opensm
	success $"$prog startup"
    else
	failure $"$prog startup"
    fi
    echo
    return $RETVAL
}

stop(){
    echo -n $"Stopping $prog: "
    killproc $prog
    RETVAL=$?
    echo
    rm -f /var/lock/subsys/opensm
    return $RETVAL

}

reload(){
    stop
    start
}

restart(){
    stop
    start
}

condrestart(){
    [ -e /var/lock/subsys/opensm ] && restart
    return 0
}


# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	status $prog
	;;
    restart)
	restart
	;;
    reload)
	reload
	;;
    condrestart)
	condrestart
	;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
	RETVAL=1
esac

exit $RETVAL
