#!/bin/bash
# ------------------------------------------------------------------------------
# GTS DCS auto-start
#
# description: Auto-starts opengts
# processname: opengts
# pidfile: /var/run/opengts.pid
#
# ------------------------------------------------------------------------------
# This script needs to be installed as follows: (as user 'root')
#    chmod 755 /etc/init.d/opengts
#    ln -s /etc/init.d/opengts /etc/rc1.d/K99opengts
#    ln -s /etc/init.d/opengts /etc/rc2.d/S99opengts
# ------------------------------------------------------------------------------

# - setup environment variables
. /usr/local/gts_vars.env

# - just to specified argument
case $1 in
   start)
       # --- this should be executed as user $GTS_USER
       #sh ${GTS_HOME}/bin/startServers.sh -start
       echo -n $"Starting GTS DCS modules ... "
       /bin/su ${GTS_USER} -c '${GTS_HOME}/bin/startServers.sh -start'
       ;;
   stop)  
       # --- this should be executed as user $GTS_USER
       #sh ${GTS_HOME}/bin/startServers.sh -kill
       echo -n $"Stopping GTS DCS modules ... "
       /bin/su ${GTS_USER} -c '${GTS_HOME}/bin/startServers.sh -kill'
       ;;
   restart)
       # --- this should be executed as user $GTS_USER
       #sh ${GTS_HOME}/bin/startServers.sh -kill
       echo -n $"Stopping GTS DCS modules ... "
       /bin/su ${GTS_USER} -c '${GTS_HOME}/bin/startServers.sh -kill'
       sleep 4
       #sh ${GTS_HOME}/bin/startServers.sh -start
       echo -n $"Starting GTS DCS modules ... "
       /bin/su ${GTS_USER} -c '${GTS_HOME}/bin/startServers.sh -start'
       ;;
esac   
exit 0
