#! /bin/bash
#
# openib       Bring up/down opensm
#
# chkconfig: 2345 9 91
# description: Activates/Deactivates open infiniband management.
#
### BEGIN INIT INFO
# Provides: $network
### END INIT INFO

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

CWD=`pwd`

# See how we were called.
case "$1" in
  start)
	action $"Loading core module: " /sbin/modprobe ib_core
	action $"Loading mad module: " /sbin/modprobe ib_mad
	action $"Loading sa module: " /sbin/modprobe ib_sa
	action $"Loading umad module: " /sbin/modprobe ib_umad
	action $"Loading mthca module: " /sbin/modprobe ib_mthca
	action $"Loading ping module: " /sbin/modprobe ib_ping
	action $"Loading ipoib module: " /sbin/modprobe ib_ipoib
	action $"Loading cm module: " /sbin/modprobe ib_cm
	action $"Loading ucm module: " /sbin/modprobe ib_ucm
	action $"Loading sdp module: " /sbin/modprobe ib_sdp
	action $"Loading at module: " /sbin/modprobe ib_at
	sleep 2;
	/usr/local/bin/opensm -V &
        touch /var/lock/subsys/openib
        ;;
  stop)
    	echo -n $"Stopping opensm: "

    	killproc opensm -TERM
    	RETVAL=$?
    	echo
    	if [ $RETVAL -eq 0 ]; then
		rm -f /var/lock/subsys/openib
    	fi
        ;;
  status)
	PORT1_STATUS=`cat /sys/class/infiniband/mthca0/ports/1/state`
	echo "Infiniband Port 1 is : $PORT1_STATUS"

	PORT2_STATUS=`cat /sys/class/infiniband/mthca0/ports/2/state`
	echo "Infiniband Port 2 is : $PORT2_STATUS"
	;;
  restart|reload)
        cd "$CWD"
	$0 stop
	sleep 10;
	$0 start
	;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit 0
