1.编写run.sh
上传jar后在当前目录新建run.sh
不外挂配置启动
vi run.sh
#!/bin/sh
if [ `ps ax |grep -v grep |grep 'test.jar' |awk '{print $1}'`"a" = "a" ] ;then echo "no pid to kill"; else kill -9 `ps ax |grep -v grep |grep 'test.jar' |awk '{print $1}'`; fi
cd /home/test
nohup java -Xms500m -Xmx1g -Xmn500m -jar test.jar > console.txt 2>&1 &
tail -f console.txt
注:
需要自行替换 test.jar 为自己的jar包名称
cd /home/test 需要替换成自己的目录
外挂配置文件启动(需要把application.yml 放到当前目录)
#!/bin/sh
if [ `ps ax |grep -v grep |grep 'test.jar' |awk '{print $1}'`"a" = "a" ] ;then echo "no pid to kill"; else kill -9 `ps ax |grep -v grep |grep 'test.jar' |awk '{print $1}'`; fi
cd /home/testnohup java -jar test.jar --spring.config.addition-location=./application.yml > console.txt 2>&1 &
tail -f console.txt
2.运行
执行命令:
./run.sh
如果出现提示
Permission denied
解决的办法:
sudo chmod -R 777 run.sh
如果提示: -bash: ./sh.sh: /bin/sh^M: bad interpreter: No such file or directory
解决办法:
sed -i -e 's/\r$//' run.sh
喜欢请关注“蛋皮皮”公众号,更多java知识分享哦~
网友评论