#!/bin/bash
#
# SANController      Script to start and stop the Onapp Integrated Storage.
#
# Author:       Julian Chesterfield <julian@onapp.com>
#
# chkconfig: 35 99 00
# description: Starts and stops the Onapp Integrated Storage.

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

LOCKFILE=/var/lock/subsys/SANController
NODEINITPROG=initSAN
NODESTOPPROG=stopSAN

stop()
{
    echo -n "Stopping Integrated Storage $NODESTOPPROG "
    $NODESTOPPROG
    if [ $? -eq 0 ]; then echo_success; else echo_failure; fi
    if [ -f $LOCKFILE ]; then rm $LOCKFILE; fi
}

start()
{
    if [ -f $LOCKFILE ]; then 
        echo -e "Integrated Storage already running (lockfile exists)"
        return; 
    fi

    echo -n "Starting Integrated Storage $NODEINITPROG "
    $NODEINITPROG
    if [ $? -eq 0 ]; then echo_success; else echo_failure; fi
    touch $LOCKFILE
}

case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    start
    ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
	;;
esac

echo
