You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
2.4 KiB

#! /bin/sh
image_name=$1
image_port=$2
registry_url=$3
eureka_url=$4
profile_server=$5
profile=$6 #--spring.profiles.active=xxxx
host_port=$2
image_tag=latest
echo "image_name:${image_name}"
echo "image_port:${image_port}"
echo "image_tag:${image_tag}"
echo "registry_url:${registry_url}"
echo "eureka_url:${eureka_url}"
echo "profile_server:${profile_server}"
echo "profile:${profile}"
# 截取到服务名称,如fastwave/fastwave-service-admin,载取后变为fastwave-service-admin
echo "(1)截取到服务名称:$1"
service_withprefix_name=$1
service_name_array=(${service_withprefix_name//\// })
service_name=${service_name_array[1]}
#向eureka发送指令,让服务停止,即不再接收新的请求,这样终止服务将更柔性化
echo "(2) nohup sh /data/jenkins_shell/disable_service.sh ${service_name} ${image_port} ${eureka_url}"
nohup sh /data/jenkins_shell/disable_service.sh ${service_name} ${image_port} ${eureka_url}
# 休眠一段时间,建议设置超过90秒以上,演示可以设置为30秒
# sleep 2m
sleep 30s
# 备份镜像到镜像仓库
# echo "(3)备份镜像到镜像仓库"
#/data/jenkins_shell/backup_image_eureka.sh $image_name $image_tag $registry_url $profile_server
#两个可以不用停止WEB服务就可以清空nohup.out的命令。
#第一种:cp /dev/null nohup.out
#第二种:cat /dev/null > nohup.out
cp /dev/null nohup.out
#sleep 2m
#停掉容器、删除容器、删除镜像
echo "(4) 停掉容器、删除容器、删除镜像"
/data/jenkins_shell/delete_image.sh $image_name $image_tag
#pull镜像 如果是两个虚拟机,则从要部署的机器195拉取136,这里是阿里云,无法拉取本地的镜像,所有这里注释掉
#echo "(5) pull镜像"
#echo "docker pull $image_name:$image_tag"
docker pull localhost:5001/${image_name}
# 将运行的镜像,重新修改tag命名为server
docker tag localhost:5001/${image_name}:${image_tag} ${image_name}:${image_tag}
#将本地刚重命名的镜像删除
echo "docker rmi localhost:5001/${image_name}:${image_tag}"
docker rmi localhost:5001/${image_name}:${image_tag}
#运行镜像
echo "(6) 运行镜像 "
echo "docker run --restart=always --name renren-register -d --network=host -t ${image_name}:$image_tag ${profile}"
#docker run --restart=always --name renren-register -d --network=host -t ${image_name}:$image_tag ${profile}
docker run --restart=always --name renren-register -d --network=host -t ${image_name}:$image_tag ${profile}