在开发中一般都会使用linux作为服务器,今天记录一下使用shell脚本启动java项目
#!/bin/bash
JAR_NAME=ruoyi-admin.jar
tpid=`ps -ef|grep $JAR_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
echo 'Stop Process...'
fi
sleep 5
tpid=`ps -ef|grep $JAR_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 $JAR_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 ./$JAR_NAME --spring.profiles.active=test >/dev/null 2>&1 &
# 开启远程调试 address为调试端口
# nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar ./$JAR_NAME > ./test.log 2>&1 &
nohup java -jar ./$JAR_NAME > ./log.log 2>&1 &
echo $! > tpid
echo 'Start Success!'