#! /bin/sh
PORT="@profiles.server.port@"
BASEDIR=`dirname $0`
BASEDIR=`(cd "$BASEDIR"; pwd)`
PROJECT_NAME="@project.artifactId@"
MAIN_CLASS="$PROJECT_NAME";
SHELL_NAME="shutdown"
SHELL_LOG="${BASEDIR}/${SHELL_NAME}.log"
CDATE=$(date "+%Y-%m-%d")
CTIME=$(date "+%H:%M:%S")

#写日志
writelog() {
  LOGINFO=$1
  echo "${CDATE} ${CTIME}: ${SHELL_NAME} : ${LOGINFO}" >>${SHELL_LOG}
  echo ${LOGINFO}
}

if [ ! -n "$PORT" ]; then  
	writelog $"Usage: $0 {port}"
	exit 9
fi


pid=`ps ax | grep -i "$MAIN_CLASS"  | grep java | grep -v grep | awk '{print $1}'`
if [ -z "$pid" ] ; then
        writelog "No Server running."
        exit 0;
fi

writelog "stoping application $PROJECT_NAME......"

kill -15 ${pid}

writelog "Send shutdown request to Server $PROJECT_NAME OK"
exit 0;


