1 问题
当项目上传至服务器后,并利用xshell成功启动项目,但当关闭xshell时项目也会跟着关闭
2 解决
编写一个重启脚本:
(1)首先新建一个文件,命名为restart.sh
(2)进入文件进行编写内容
#!/bin/sh
RESOURCE_NAME=ShareVideo.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!
(3)保存,在通过xshell,到当前目录下启动脚本
chmod +x start.sh
./start.sh
注意:脚本要和jar包在同一目录下