Linux springBoot自动启动脚本和停止脚本
一、 启动服务脚本
vim start.sh
#!/bin/bash
pid=ps -ef|grep car_insurance.jar|grep -v grep|awk '{print $2}'|wc -l
b=0
if [ $pid -gt $b ]
then
echo " car_insurance is already running!"
else
nohup /home/chuxin/server/jdk1.8.0_121/bin/java -jar car_insurance.jar --spring.profiles.active=dev >> car.log 2>&1 &
echo “car_insurance has started!”
fi
注释:/home/chuxin/server/jdk1.8.0_121/bin/java 指定springBoot启动JDK版本
–spring.profiles.active=dev 指定配置文件
car.log 2>&1 & 输出日志
二、 停止服务脚本
vim end.sh
#!/bin/bash
pid=ps -ef|grep car_insurance.jar|grep -v grep|awk '{print $2}'|wc -l
b=0
if [ $pid -gt $b ]
then
ps -ef|grep car_insurance.jar|grep -v grep|awk ‘{print $2}’|xargs kill -9
echo “internetdocking has stopped!”
else
echo “internetdocking is not running!”
fi
给脚本增加权限
chmod u+x *.sh