1.将jar包放到和该脚本同级目录
2.记得chmod 777 ./start.sh 赋予执行权限
3.执行./start.sh文件即可
4.重启也可以直接执行此文件
5.如果没有打包配置文件可以在此脚本同级目录创建config目录将yml/properties配置文件放进去
.
#!/bin/bash # 进入脚本所在路径 cd `dirname $0`;pwd # 加载java环境变量 #source /opt/script/java_export.sh # 查询进程 pkg_count=`find ./ -maxdepth 1 -name '*.jar' -or -name '*.war' | wc -l` if [ $pkg_count -eq 1 ];then JAR_PATH=`find ./ -maxdepth 1 -name '*.jar' -or -name '*.war'| sed 's#.*/##' ` CONFIG_PATH='config' else echo 'Error:101' echo $pkg_count echo 'exit' exit fi proc_count=`ps aux | grep $JAR_PATH | grep -v grep | wc -l` pid=`ps -ef | grep $JAR_PATH | grep -v grep | awk '{print $2}'` if [ $proc_count -eq 1 ] then echo '进程存在 关闭进程' echo $pid `kill -9 $pid` fi echo "开始启动" # jdk8 nohup java -jar -Xms2012m -Xmx2012m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8401 -Dfile.encoding=UTF-8 -Dcas.standalone.config="$CONFIG_PATH" "$JAR_PATH" > nohup.out 2>&1 & # 大于jdk8 # nohup java -jar -Xms2012m -Xmx2012m -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:8401 -Dfile.encoding=UTF-8 -Dcas.standalone.config="$CONFIG_PATH" "$JAR_PATH" > nohup.out 2>&1 & tail -f nohup.out
标签:grep,springboot,JAR,jar,echo,start,sh,nohup,PATH From: https://www.cnblogs.com/guanxiaohe/p/17819200.html