注意:目前jenkins用户启动,切记。jenkins用户密码和root相同
版本一
jenkins登录
[root@prd-live-dubbo02 back-service]# su jenkins
[jenkins@prd-live-dubbo02 back-service]$ exit
exit
[root@prd-live-dubbo02 back-service]#
autoDeploy.sh
source /etc/profile
deploy_back(){
cd /mnt/source/server-service-source/server-service
git pull origin dev-maven
echo 'git拉取server-admin项目dev-mavne分支代码完成!'
cd /mnt/source/server-service-source/server-service/back-service
mvn clean package -P dev
echo 'server-admin项目打包完成!'
/mnt/soft/tomcat-service-1/back_service_boot.sh
}
if [ ! -n "$1" ] ;then
deploy_back
else
if [ $1 = "deploy_back" ] ;then
deploy_back
else
echo "don't recognize parm!"
fi
fi
back_service_boot_sh
#! /bin/sh
echo '####################开始自动部署####################'
path=`pwd`
PID=$(ps -fu `whoami`|grep tomcat-service-1|grep -v grep|awk '{print $2}')
if [ -z "$PID" ];then
echo 'no tomcat process'
else
ps -fu `whoami`|grep tomcat-service-1|grep -v grep|awk '{print $2}'|xargs kill -9
kill -9 "$PID"
fi
sleep 5
cd /mnt/soft/tomcat-service-1/webapps
rm -fr back-service
mv /mnt/soft/video-service/webapps/video-service.war /mnt/soft/video-service-bak/video-service.war.$(date +%Y%m%d)
cp /mnt/source/server-service-source/server-service/video-service/target/video-service.war /mnt/soft/video-service/webapps/
echo 'server-admin.war拷贝到/mnt/soft/server-admin/webapps/目录完成!'
sleep 2
cd /mnt/soft/video-service/bin
echo '执行重启tomcat'
./startup.sh
echo '####################部署结束####################'
版本二
api-restart_sh
#!/bin/bash
#
# Firstly find the process of the tomcat....
TOMCAT_PROCESS_STR=`ps aux | grep 'java.*server-api' | grep -v grep`
PROCESS_ARRAY=(${TOMCAT_PROCESS_STR// / })
TOMCAT_PROCESS_ID=${PROCESS_ARRAY[1]}
echo $TOMCAT_PROCESS_ID
#
# Secondly send stop tomcat to see if we can kill it
#stoptomcat
sleep 12
#
# Last we'll use kill tomcat process in a looking up loop
for ((a=1;a<=5;a++))
do
CHECK_STR_LENGTH=0
TOMCAT_PROCESS_CHECK_STR=`ps aux | grep 'java.*/mnt/soft/server-api' | grep -v grep`
CHECK_STR_LENGTH=${#TOMCAT_PROCESS_CHECK_STR}
if [ $CHECK_STR_LENGTH != 0 ]
then
kill -9 $TOMCAT_PROCESS_ID
sleep 5
echo Try to kill tomcat once more...
else
echo Tomcat is already killed
break
fi
done
echo "clear server-api"
cd /mnt/soft/server-api/webapps/
mv /mnt/soft/server-api/webapps/server-api.war /mnt/soft/bak/erver-api.war.$(date +%Y%m%d)
rm -rf *
echo "copy server-api"
mv /data/www/server-api/target/* /mnt/soft/server-api/webapps/
/mnt/soft/server-api/bin/startup.sh &
|
|