启动
编写启动脚本 startup.sh
#!/bin/bash
echo Starting application
nohup java -jar springboot_helloword-0.0.1-SNAPSHOT.jar --spring.profiles.active=pro >> springboot_helloword.log &
或者
#!/bin/bash
echo Starting application
nohup java -jar lixing-0.0.1-SNAPSHOT.jar --spring.profiles.active=pro > nohup.out 2>&1 &
- 其中
--spring.profiles.active=pro
是用来指定配置文件环境的。
授权
chmod u+x startup.sh
关闭
编写关闭脚本 stop.sh
#!/bin/bash
PID=$(ps -ef | grep springboot_helloword-0.0.1-SNAPSHOT.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo Application is already stopped
else
echo kill $PID
kill $PID
fi
授权
chmod u+x stop.sh
重启
编写重启脚本 restart.sh
#!/bin/bash
echo Stopping application
source ./stop.sh
echo Starting application
source ./startup.sh
授权
chmod u+x restart.sh
参考:springboot以jar包方式启动、关闭、重启脚本
nohup.log日志过大问题处理(清空nohup.out日志)
cp /dev/null > nohup.out