#!/bin/bash
bashParam="$-"
if [ 0 -eq $# ]; then
echo "Need param $0 <start|stop|restart> "
fi
OPERATION=$1
#SYNDATA_HOME=$(cd "$(dirname "$0")" && pwd)
CUR_DIR=$(cd `dirname "$0"`; pwd)
SYNDATA_HOME=$(cd ${CUR_DIR}/..; pwd)
JAVAHOME=${SYNDATA_HOME}/jdk1.8.0_161/bin
PID_FILE=${CUR_DIR}/bin/app.pid
PID=""
if [[ -f ${PID_FILE} ]]; then
PID=$(cat "${PID_FILE}")
fi
startTomcat() {
if [[ ! -f ${PID_FILE} ]];then
echo "Start tomcat service."
if [ ! -d "${SYNDATA_HOME}"/logs ]; then
mkdir -p "${SYNDATA_HOME}"/logs
fi
echo "nohup ${JAVAHOME}/java -jar -Dspring.config.location=${SYNDATA_HOME}/config/ ${SYNDATA_HOME}/libs/syndata-web.jar > ${SYNDATA_HOME}/logs/syndata.log 2>&1 &"
nohup "${JAVAHOME}"/java -jar -Dspring.config.location="${SYNDATA_HOME}"/config/ "${SYNDATA_HOME}"/libs/syndata-web.jar > "${SYNDATA_HOME}"/logs/syndata.log 2>&1 &
echo "Tomcat service start."
else
echo "Tomcat is already running, since the PID file existed."
fi
}
stopTomcat() {
echo 'Stop tomcat service.'
kill -9 "${PID}" &> /dev/null
# shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo "Tomcat stop succeed."
else
echo "Tomcat stop failed."
fi
rm -f "${PID_FILE}"
}
case ${OPERATION} in
"start")
startTomcat
;;
"stop")
stopTomcat
;;
"restart")
stopTomcat
startTomcat
;;
*)
echo "unknown operation $OPERATION"
exit 1
;;
esac
启动命令输出:
nohup /opt/skyvis/zntsdownload/syndata-1.0.0/jdk1.8.0_161/bin/java -jar -Dspring.config.location=/opt/skyvis/zntsdownload/syndata-1.0.0/config/ /opt/skyvis/zntsdownload/syndata-1.0.0/libs/syndata-web.jar > /opt/skyvis/zntsdownload/syndata-1.0.0/logs/syndata.log 2>&1 &