LinuxDocker-Podman

非固定IP jenkins 布署 docker 脚本

2018-01-15  本文已影响20人  ___n
#!/usr/bin/env bash


echo ${1} "开始处理容器"

container_name=$1

echo '准备处理 '${1}

screen_name=`screen -list | grep "shopSys" | awk '{print $1}' 2> /devnull`


screen -S $container_name  -X quit
screen -wipe

docker_status=`docker ps -a | grep demo_"${1}" | awk '{print $1}' 2> /devnull`

if [ ! $docker_status ];then

    echo '容器不存在 '${container_name}
    echo '启动 '${container_name}

else

    docker stop $docker_status
    echo '停止 '${container_name} ' - ' ${docker_status}
    docker rm $docker_status
    echo '删除 '${docker_status}

fi


screen -S $container_name -dm docker run -it --rm -p 9502:9501 --name demo_$container_name -v /var/www/demo/$container_name:/var/www/demo/$container_name -w /var/www/demo/$container_name php7 php /var/www/demo/$container_name/examples/app_server.php start

echo '启动 '${container_name} '完成,正在检测是否启动成功'
sleep 5s
container_id=`docker inspect -f '{{.Id}}' demo_$container_name 2> /dev/null`
if [ ! $container_id ];then
    echo "容器启动失败"
    exit 2
else
    echo "容器启动完成"
    exit 0
fi

启动参数

cd $WORKSPACE
rm -fr .svn
tar zcf ../demoshopSysUpdatePack.tar.gz --exclude=app_server.pid --exclude=cache --exclude=logs *
cd ..
scp -r demoshopSysUpdatePack.tar.gz root@192.168.1.220:/var/www/demo
rm -fr demoshopSysUpdatePack.tar.gz
ssh root@192.168.1.220 'cd /var/www/demo && rm -fr /var/www/demo/shopSys/* && tar zxf demoshopSysUpdatePack.tar.gz -C shopSys && rm -fr /var/www/demo/demoshopSysUpdatePack.tar.gz && chown nobody:nobody -R shopSys &&  /var/www/demo/demo_shopSys.sh shopSys'



#!/usr/bin/env bash


echo ${1} "开始处理容器"

container_name=$1

echo '准备处理 '${1}

screen_name=`screen -list | grep "shopSys" | awk '{print $1}' 2> /devnull`


screen -S $container_name  -X quit
screen -wipe

docker_status=`docker ps -a | grep demo_"${1}" | awk '{print $1}' 2> /devnull`

if [ ! $docker_status ];then

    echo '容器不存在 '${container_name}
    echo '启动 '${container_name}

else

    docker stop $docker_status
    echo '停止 '${container_name} ' - ' ${docker_status}
    docker rm $docker_status
    echo '删除 '${docker_status}

fi

screen -S $container_name -dm docker run -it --rm -p 9502:9501 --name demo_$container_name -v /var/www/demo/$container_name:/var/www/demo/$container_name -w /var/www/demo/$container_name deploy/php7 php /var/www/demo/$container_name/examples/app_server.php start

echo '启动 '${container_name} '完成,正在检测是否启动成功'
sleep 5s
container_id=`docker inspect -f '{{.Id}}' demo_$container_name 2> /dev/null`
if [ ! $container_id ];then
    echo "容器启动失败"
    exit 2
else
    echo "容器启动完成"
    exit 0
fi

上一篇 下一篇

猜你喜欢

热点阅读