#! /bin/bash

APP_ROOT_DIR=/home/gmt/app

NAME_SERVICE=EyeAPN_AsdeRecv
NAME_JAR=EyeAPN_AsdeRecv.jar
NAME_PID=application.pid


PATH_EXE_ROOT=$APP_ROOT_DIR/$NAME_SERVICE
PATH_EXE_JAR=$PATH_EXE_ROOT/$JAR_NAME

PATH_CONFIG=$PATH_EXE_ROOT/cfg

OPT_JAVA="-Dfile.encoding=UTF-8"
OPT_SPRING="--spring.config.location=file:$PATH_CONFIG/application.yml"


cd $PATH_EXE_ROOT

if [ -f $NAME_PID ]; then
        PID=$(cat $PATH_EXE_ROOT/$NAME_PID);
        echo "$NAME_SERVICE stoping(${PID}) ..."
		if [ -n "${PID}" ]; then
			kill -9 $PID;
		fi
        echo "$NAME_SERVICE stopped(${PID}) ..."
        rm $NAME_PID
else
	PID=$(ps ax | grep $NAME_SERVICE | grep -v 'grep' | grep -v $0 | awk '{print $1}')

	if [ -n "${PID}" ]; then
			echo pid : ${PID} / length : ${#PID}
			echo "$NAME_SERVICE stoping ..."
			kill -9 $PID;
			echo "$NAME_SERVICE(${PID}) stopped ..."
	else
			echo "$NAME_SERVICE is not running ..."
	fi
fi
exit 0

