java spring boot jar包的启动shell脚本
最近有人找我要shell启动脚本,忘记从那复制过来改的了,需要的拿走不谢。使用比较简单 ./start.sh **.jar start/stop/status/restart 等。参数自己改改不难看懂。
#!/bin/bash
export JAVA_HOME=/usr/local/java/jdk1.8.0_211
export JRE_HOME=${JAVA_HOME}/jre
APP_HOME=/app/springboot/group-service
APP_NAME=$1
usage() {
echo "Usage: sh boot [APP_NAME] [start|stop|restart|status]"
exit 1
}
is_exist(){
PID=$(ps -ef |grep ${APP_NAME} | grep -v $0 |grep -v grep |awk '{print $2}')
if [ -z "${PID}" ]; then
return 1
else
return 0
fi
}
start(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is already running, PID=${PID}"
else
nohup ${JRE_HOME}/bin/java -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=512m -XX:SurvivorRatio=6 -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=80 -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark -XX:+PrintGCDateStamps -verbose:gc -XX:+PrintGCDetails -Xloggc:gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=dump.hprof -jar ${APP_HOME}/${APP_NAME} --spring.profiles.active=pro ----server.port=9001 > /dev/null 2>&1 &
PID=$(echo $!)
echo "${APP_NAME} start success, PID=$!"
fi
}
stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 ${PID}
echo "${APP_NAME} process stop, PID=${PID}"
else
echo "There is not the process of ${APP_NAME}"
fi
}
restart(){
stop
start
}
status(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is running, PID=${PID}"
else
echo "There is not the process of ${APP_NAME}"
fi
}
case $2 in
"start")
start
;;
"stop")
stop
;;
"restart")
restart
;;
"status")
status
;;
*)
usage
;;
esac
exit 0