腳本需要與springboot jar在同級目錄。
#!/bin/bash
### stop function
### $1: pid.
function stop {
kill -15 $1
}
# function run jar
## $1 jar file name
function runJars {
nohup $JAVA_HOME/bin/java -jar $1 >/dev/null &
}
# Restart function
# $1: Jar file name
function reStart {
jarFileName=$(ls -l|grep $1 | awk '{print$9}')
pid=$(pgrep -f $jarFileName | awk '{print$1}')
echo "***************$1********************"
if [ ! -n "$pid" ]; then
echo "$jarFileName is not started yet. Start now!"
runJars $jarFileName
echo "*************************************************"
else
echo "$jarFileName is running!(pid: $pid). Kill (with '-15 ')now!"
stop $pid
if [ $? -eq 0 ];then
echo "kill $1 success! Try to start now!"
runJars $jarFileName
echo "*************************************************"
else
echo "Error: kill $1 process failed. PID: $pid"
fi
fi
}
#??部分無需修改
# 修改這里的web修改成你的jar包的名稱(沒必要全寫)
reStart "web"