#! /bin/sh
#
# PURPOSE: Script to start, stop and restart the FlexRAID server
#
# AUTHOR: feedback[AT]HaveTheKnowHow[DOT]com
#

set -e

LOGDIR=/var/log
RUNDIR=/var/run
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

#export LANG LANGUAGE

test -x /var/lib/flexraid/FlexRAID || exit 0

case "$1" in
  start)
        echo "Starting FlexRAID Server: "
        start-stop-daemon -S -o -b -d /var/lib/flexraid/ -x /var/lib/flexraid/FlexRAID
        echo "FlexRAID started"
        ;;
  stop)
        echo "Stopping FlexRAID Server: "
        start-stop-daemon -K -o -x /var/lib/flexraid/FlexRAID
        echo "FlexRAID stopped"
        ;;

  restart)
        echo "Restarting FlexRAID Server: "
        start-stop-daemon -K -o -x /var/lib/flexraid/FlexRAID
        sleep 1
        start-stop-daemon -S -o -b -d /var/lib/flexraid/ -x /var/lib/flexraid/FlexRAID
        echo "FlexRAID restarted"
        ;;
  *)
        N=/etc/init.d/FlexRAID
        echo "Usage: $N {start|stop|restart}" >&2
        exit 1
        ;;
esac