#!/bin/bash
PORT="@profiles.server.port@"
PROJECT_NAME="@project.artifactId@";
MAIN_CLASS="$PROJECT_NAME-@project.version@.jar";
SHELL_NAME=$0
SHELL_LOG="${SHELL_NAME}.log"

LOG_DATE='date "+%Y-%m-%d"'
LOG_TIME='date "+%H-%M-%S"'

CDATE=$(date "+%Y-%m-%d")
CTIME=$(date "+%H-%M-%S")

#写日志
writelog() {
  LOGINFO=$1
  echo "${CDATE} ${CTIME}: ${SHELL_NAME} : ${LOGINFO}" >>${SHELL_LOG}
}
jcpid=`ps -ef | grep -v "grep" | grep "$MAIN_CLASS" | grep "app.port=$PORT" | sed -n '1P' | awk '{print $2}'`

if [ $jcpid ]; then
		writelog "The $PROJECT_NAME start finished, PID is $jcpid"
		exit $SUCCESS
	else
    writelog "start service..."
    systemctl stop ${PROJECT_NAME} && systemctl start ${PROJECT_NAME}
fi

