PROJECT_NAME=route
APP_HOME=$(dirname $(pwd))/$PROJECT_NAME
JAVA_LIB_PATH=$APP_HOME/resource/daemon/lib
JAVA_HOME=/home/software/jdk1.8
CLASS_PATH=$APP_HOME/resource/daemon/route.jar
JAVA_OPTS=-Xms512m -Xmx512m -Xnoclassgc -Xverify:none
MAIN_CLASS=com.dice.game.StartupWrapper
PID_FILE=${APP_HOME}/${PROJECT_NAME}.pid
LOG_FILE=${APP_HOME}/logs/${PROJECT_NAME}.out
if [ ! -f "$PID_FILE" ]; then
touch "$PID_FILE"
echo 0 > $PID_FILE
fi
if [ ! -f "$LOG_FILE" ]; then
touch "$LOG_FILE"
fi
echo "service name: $PROJECT_NAME"
echo "app home: $APP_HOME"
echo "java home: $JAVA_HOME"
echo "class path: $CLASS_PATH"
echo "main class: $MAIN_CLASS"
echo "pid file : $PID_FILE"
pid=0
getpid() {
pid=`cat $PID_FILE`
}
start() {
getpid
if [ $pid -ne 0 ]; then
echo "================================"
echo "warn: already started! or bad close last time!"
echo "================================"
fi
echo -n "Starting..."
nohup $JAVA_HOME/bin/java -server $JAVA_OPTS -classpath $CLASS_PATH $MAIN_CLASS >> $LOG_FILE 2>&1 & echo $! > $PID_FILE
getpid
if [ $pid -ne 0 ]; then
echo "================================="
echo "[Start Success] (pid=$pid)"
echo "================================"
else
echo "================================="
echo "[Start Failed]"
echo "================================="
fi
}
stop() {
getpid
if [ $pid -ne 0 ]; then
skill -15 $pid
echo "================================"
echo "stoping"
echo "================================"
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0