#!/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 frontend
    if [ $? -eq 0 ]; then
        echo_success;
        if [ -f $LOCKFILE ]; then rm $LOCKFILE; fi
    else
        echo_failure;
    fi
}

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

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

updateconfig()
{
    if [ ! -f $LOCKFILE ]; then
        echo -e "Integrated Storage not running (can not update config)"
        return;
    fi

    echo -n "Update Config Integrated Storage"
    $NODEINITPROG updateconf
    if [ $? -eq 0 ]; then echo_success; else echo_failure; fi
}

st_status()
{
    status NODEINITPROG
}

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

echo
