port=20000
#war包名称
name=$1
#war包要部署的地方
path=$2
#jenkins放war包的地方
path_w=$3
#pid名称
pid_name="${4}.pid"
pid="$(cat /var/run/"${pid_name}")"
#$(ps -ef | grep java | grep $name | awk '{print $2}')
echo "s1 = $name"
echo "s2 = $path"
echo "s3 = $path_w"
echo "pid = $pid"
#rm the war if exist
echo "$path/$name"
if [ -f "$path/$name" ];then
echo "delete the file $name"
rm -f $path/$name
else
echo "the file $name is not exist"
fi
sleep 1s
#copy the war
cp $path_w/$name $path/
echo "copy the file $name from $path_w to $path"
#shundow the process if exist
if [ $pid ];then
kill -9 $pid
echo "kill the process $name pid = $pid"
else
echo "process is not exist"
fi
sleep 1s
#start the application
#要切换到项目目录下才能在这里生成日志
cd $path
#防止被jenkins杀掉进程
BUILD_ID=dontKillMe
nohup java -server -Xms256m -Xmx512m -jar -Dserver.port=$port $name >> nohup.out 2>&1 &
sleep 1s
pid_new=$(ps -ef | grep java | grep $name | awk '{print $2}')
if [ $? -eq 0 ];then
echo "this application $name is starting pid_new = $pid_new and port = $port"
else
echo "this application $name startup failure"
fi
echo $! > /var/run/$pid_name
echo "over"
#!/bin/bash
PID=$(cat /var/run/contract.pid)
kill -9 $PID
echo "this application been shutdown"