脚本内容(build.sh):
#!/bin/sh
export JAVA_HOME=/usr/local/jdk-11.0.8/jdk-11.0.8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
echo "find target pid"
pids=`ps aux | grep target`
echo $pids
OLD_IFS="$IFS"
IFS=" "
array=($pids)
pid=${array[1]}
echo $pid
kill_s="kill -9 $pid"
echo $kill_s
`$kill_s`
echo "start target"
`nohup java -jar targ*.jar --spring.profiles.active=dev > log.txt 2>&1 & `
nextpids=`ps aux | grep target`
echo $nextpids
OLD_IFS="$IFS"
IFS=" "
array=($nextpids)
nextpid=${array[1]}
echo $pid "|" $nextpid
if test $pid -eq $nextpid
then
echo "deploy fail"
else
echo "deploy sucess"
fi
执行脚本:
bash build.sh
效果如下: