#!/bin/bash
#
# SANNetwork      Script to start and stop the Onapp Integrated Storage Network.
#
# Author:       Andriy Melnyk <andriy.melnyk@onapp.com>
#
# chkconfig: 35 99 00
# description: Starts and stops the Onapp Integrated Storage Network.

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

LOCKFILE=/var/lock/subsys/SANNetwork
NODEINITPROG=/usr/pythoncontroller/SANNetwork.pyc

stop()
{
    echo -n "Stopping Integrated Storage Network $NODEINITPROG\n"
    /usr/pythoncontroller/python /usr/pythoncontroller/SANNetwork.pyc stop
    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 Network already up (lockfile exists)\n"
        return; 
    fi

    echo -n "Starting Integrated Storage Network $NODEINITPROG\n"
    /usr/pythoncontroller/python /usr/pythoncontroller/SANNetwork.pyc start
    if [ $? -eq 0 ]; then
        echo_success;
        touch $LOCKFILE
    else
        echo_failure;
    fi
}

st_status()
{
    status $NODEINITPROG
}

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

echo
