#启动参数
START_OPTS=$3
#AppName=biz-score-service
##!/bin/bash
SpringBoot=$2
#JVM参数
JVM_OPTS="-Dname=$SpringBoot -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=512M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
#JVM_OPTS="-server -Dspring.profiles.active=prod -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=512M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
#JVM_OPTS="-Dname=$SpringBoot -Duser.timezone=Asia/Shanghai -Xms512M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
#APP_HOME=`pwd`
LOG_PATH=/opt/service/$AppName/logs/$AppName.log
if [ "$1" = "" ];
then
echo -e "未输入操作名 {start|stop|restart|status}"
exit 1
fi
if [ "$SpringBoot" = "" ];
then
echo -e "未输入应用名"
exit 1
fi
function start()
{
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "$SpringBoot is running..."
else
echo "Start $SpringBoot success..."
nohup java -jar $JVM_OPTS $SpringBoot $START_OPTS > /dev/null 2>&1 &
fi
}
function stop()
{
echo "Stop $SpringBoot"
boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
if [ $count != 0 ];then
kill $boot_id
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
boot_id=`ps -ef |grep java|grep $SpringBoot|grep -v grep|awk '{print $2}'`
kill -9 $boot_id
fi
}
function restart()
{
stop
sleep 2
start
}
function status()
{
count=`ps -ef |grep java|grep $SpringBoot|grep -v grep|wc -l`
if [ $count != 0 ];then
echo "$SpringBoot is running..."
else
echo "$SpringBoot is not running..."
fi
}
#使用说明,用来提示输入参数
function usage() {
echo "Usage: sh jspt-service.sh [start|stop|restart|status] appName startOption"
exit 1
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
echo -e "Usage: sh $0 {start|stop|restart|status} {SpringBootJarName} Example: sh $0 start esmart-test.jar"
esac
取名 xxx.sh
遇到权限不够问题
chmod 777 xxx.sh
使用方法:
启动:./xxx.sh start (jar包名称)
重启:./xxx.sh restart (jar包名称)
停止:./xxx.sh stop (jar包名称)