1.后台启动 startTest.sh
#设置工程路径 project_path=/root/test cd $project_path #nohup后台启动,输出日志到test.log nohup java -jar test.jar >test.log & #打印日志 tail -f test.log
文件可执行权
chmod +x startTest.sh
执行 ./startTest.sh
2.根据应用端口关闭服务 stopTest.sh
#设置关闭的端口 port=8080 #获取此端口运行的进程 pid=`lsof -t -i:$port` #判断如果进程号不为空则,关闭进程 if test -z "$pid";then echo "test 工程未启动!" else kill -9 $pid echo "test 工程进程$pid 关闭成功!"文件赋执行权同上
文章来源: 后台启动和关闭jar的shell脚本