docker - solo 自动升级部署脚本 - V1.0.0
docker - solo 自动升级部署脚本 - V1.0.0
- feature
- 检测
solo
版本是否有新版本; - 可自动删除更新后的
solo
、Lute
镜像包; - 自动检测
solo
是否安装部署成功,不成功则再次pull
镜像 - 检测
lute-http
是否正常运行 - 修复有
Lute
更新包更新后时往往因为solo
进程占用Lute
进程,原镜像无法删除
#!/bin/bash
# @Solo docker 升级脚本&删除旧的镜像脚本
# @Author: lonuslan
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
start_time=`date +'%Y-%m-%d %H:%M:%S'`
solo(){
echo "-----------------solo upgrading------------------------------"
docker pull b3log/solo
docker stop solo
docker run --detach --name solo --network=host \
--env RUNTIME_DB="MYSQL" \
--env JDBC_USERNAME="lonuslan" \
--env JDBC_PASSWORD="*******" \
--env JDBC_DRIVER="com.mysql.cj.jdbc.Driver" \
--env JDBC_URL="jdbc:mysql://rm-bp1i894o95w363361xo.mysql.rds.aliyuncs.com:3306/solo? useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC" \
--volume /dockerData/solo/Bubble/:/opt/solo/skins/Bubble/ \
--rm \
b3log/solo --listen_port=9292 --lute_http=http://localhost:8249 --server_scheme=https --server_host=www.lonuslan.com --server_port=
}
#--------------------------删除无用镜像image包--------------------------#
del(){
num=`docker images |grep none |wc -l`
echo "当前存在无用镜像包$num 个."
for ((i=1;i<=$num;i++))
do
images=`docker images |grep none | awk '{print $3}'`
docker rmi $images
if [[ $? == 0 ]];
then
echo -e "------------------$end_time 删除镜像id:$images 成功-----------------------"
else
echo -e "-----------------$end_time 删除镜像id:$images 失败 -----------------------"
fi
done
}
#---------------------------lute安装脚本--------------------------------
lute(){
docker pull b3log/lute-http
docker stop solo
docker stop lute
docker rm lute
docker run --detach --name lute --rm --network=host b3log/lute-http
}
solo_time(){
end_time=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$start_time" +%s);
end_seconds=$(date --date="$end_time" +%s);
echo "脚本运行所用时间为:"$((end_seconds-start_seconds))"s"
echo "开始时间为: $start_time ,结束时间为:$end_time"
echo " "
}
#----------------------------判断solo是否有新版本-------------------------------------
upgrade_solo(){
isUpgrad=$(docker pull b3log/solo|grep "Downloaded")
if [[ -z $isUpgrad ]]
then
echo $start_time :Detection solo version is the latest version
else
solo
fi
}
#---------------------------判断lute是否有新版本----------------------------------
upgrade_lute(){
isUpgrad=$(docker pull b3log/lute-http|grep "Downloaded")
if [[ -z $isUpgrad ]]
then
echo $start_time :Detection lute version is the latest version
else
lute
fi
}
#---------------------判断docker镜像是否正常运行---------------------------
Server_test(){
server=`docker ps | grep b3log/solo`
if [ -z "$server" ]; then #如果查询结果为空,则停留5秒继续pull镜像
sleep 5
echo '----------docker-solo状态异常,重新安装------------'
solo
fi
lute_http=` docker ps | grep lute-http`
if [ -z "$lute_http" ]; then
sleep 3
lute
fi
}
main(){
upgrade_lute
upgrade_solo
Server_test
solo_time
del
}
main
#-----------------------------------------------------------------------```
- 定时任务:
00 03 * * * /shell/solo.sh >> /root/log/solo.log
docker - solo 自动升级部署脚本 - V1.0.0
本博客所有文章除特别声明外,均采用
CC BY-NC-SA 4.0
许可协议。转载请注明来自 Hi I'm LouisLan!
评论
0 评论