- 用maven打包项目后会生成一个jar包
- 将这个jar包上传到云服务器
- 写个start.sh的脚本,注意脚本和jar包同级目录,默认生效的test环境
#!/bin/sh
RESOURCE_NAME=项目打包出来的包名.jar
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
kill -15 $tpid
fi
sleep 5
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpid
else
echo 'Stop Success!'
fi
tpid=`ps -ef|grep $RESOURCE_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'App is running.'
else
echo 'App is NOT running.'
fi
rm -f tpid
nohup java -jar ./$RESOURCE_NAME --spring.profiles.active=test &
echo $! > tpid
echo Start Success!
- 更改脚本权限 chmod 644
- 直接运行即可
- 访问为ip:port,ip是云服务器的ip,port是springboot项目配置的端口