#!/bin/bash
:<<!
使用本地配置文件进行启动服务
!
#脚本只要发生错误，就终止执行
set -e
#在运行结果之前，先输出执行的那一行命令
set -x

#获取脚本所有的绝对路径
PRG="$0"
while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

# Get standard environment variables
PRGDIR=`dirname "$PRG"`
#进入脚本所在的目录
cd $PRGDIR

#设置使用本地的应用配置文件
export ENABLE_APPENV=true
export ENABLE_JVMGC=true
export ENABLE_JETTY=true


start()
{
      source ./start.sh start -d
}

stop()
{
      source ./start.sh stop
}

status() {
       source ./start.sh status
}

debug() {
       export ENABLE_JVMDEBUG=true
       source ./start.sh start -d
}


restart() {
       source ./start.sh restart -d
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  debug)
    debug
    ;;  
  restart|reload|force-reload)
    restart
    ;;
  status)
    status
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|debug}"
    RETVAL=1
esac

exit $RETVAL
