[ Cmii ] [ Octopus ] - hot fix manual shut down init queue - 2

This commit is contained in:
zeaslity
2024-04-10 10:47:32 +08:00
parent 83a676e321
commit a9a9ab859e
6 changed files with 191 additions and 10 deletions

View File

@@ -294,8 +294,8 @@ func handleInitMsgFromServer(initFromServerMsg *rabbitmq.OctopusMessage, initToS
// shutdownRegisterQueueConnection 关闭初始化连接的两个队列 // shutdownRegisterQueueConnection 关闭初始化连接的两个队列
func shutdownRegisterQueueConnection(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue) { func shutdownRegisterQueueConnection(initFromServerQueue *rabbitmq.RabbitQueue, initToServerQueue *rabbitmq.RabbitQueue) {
initFromServerQueue.ConsumeOK = false initFromServerQueue.ConsumeOK.Store(false)
initToServerQueue.ConsumeOK = false initToServerQueue.ConsumeOK.Store(false)
log.InfoF("Octopus Agent Init Queue has disconnected!") log.InfoF("Octopus Agent Init Queue has disconnected!")
} }

View File

@@ -6,6 +6,7 @@ import (
"github.com/streadway/amqp" "github.com/streadway/amqp"
"strings" "strings"
"sync" "sync"
"sync/atomic"
"wdd.io/agent-common/logger" "wdd.io/agent-common/logger"
) )
@@ -47,7 +48,7 @@ type RabbitQueue struct {
// 返回消息队列 // 返回消息队列
ReceiveChan *RabbitReceiveChan ReceiveChan *RabbitReceiveChan
// Consume 是否继续 // Consume 是否继续
ConsumeOK bool ConsumeOK atomic.Bool
} }
// RabbitMQConn is a struct that holds the connection and channel objects // RabbitMQConn is a struct that holds the connection and channel objects
@@ -195,7 +196,7 @@ func (r *RabbitQueue) Handle() chan bool {
deliveries := r.Read(true) deliveries := r.Read(true)
// 2024年4月9日 // 2024年4月9日
r.ConsumeOK = true r.ConsumeOK.Swap(true)
foreverHandle := make(chan bool) foreverHandle := make(chan bool)
// 死循环处理Octopus Message // 死循环处理Octopus Message
@@ -215,9 +216,8 @@ func (r *RabbitQueue) Handle() chan bool {
}) })
// 2024年4月9日 // 2024年4月9日
if !r.ConsumeOK { if !r.ConsumeOK.Load() {
marshal, _ := json.Marshal(r.RabbitProp) log.InfoF("Rabbit Queue of [%s] [%s[ disconnect!", r.RabbitProp.ExchangeName, r.RabbitProp.QueueName)
log.InfoF("Rabbit Queue of %s disconnect!", marshal)
break break
} }
} }

View File

@@ -0,0 +1,154 @@
#!/bin/bash
# set -o errexit
# set -o nounset
# set -o pipefail
octopus_agent_url=https://happybirthday.107421.xyz/octopus-agent
agent_config_url=https://happybirthday.107421.xyz/agent-config
agent_version_url=https://happybirthday.107421.xyz/agent-version
agent_offline_proxy_conf=https://oss-1.107421.xyz/octopus-offline-nginx.conf
default_octopus_agent_local_path=/data/github-action/octopus-agent/
default_octopus_agent_config_local_path=/data/github-action/agent-config/
default_octopus_agent_version_local_path=/data/github-action/agent-version
sync_octopus_agent() {
local octopus_agent_html="octopus_agent.html"
rm -rf ${octopus_agent_html}
wget "$octopus_agent_url/" -qO ${octopus_agent_html}
if [[ ! -s $octopus_agent_html ]]; then
echo "[sync_octopus_agent] - download agent version file error ! return false !"
return 233
fi
echo "清除旧的Agnet内容"
rm -rf ${default_octopus_agent_local_path}
mkdir -p ${default_octopus_agent_local_path}
echo ""
echo "开始同步最新版本的Octopus Agent !"
local octopus_agent_config_file_list=""
# shellcheck disable=SC2034
octopus_agent_config_file_list=$(cat ${octopus_agent_html} | grep -v h1 | grep "a href=" | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | tr "\n" " ")
local octopus_agent_config_list
IFS=" " read -ra octopus_agent_config_list <<<"$octopus_agent_config_file_list"
echo ""
local octopus_agent_file
for octopus_agent_file in "${octopus_agent_config_list[@]}"; do
echo "[sync_octopus_agent] => start to download => ${octopus_agent_url}/${octopus_agent_file}"
wget "${octopus_agent_url}/${octopus_agent_file}" -qO "${default_octopus_agent_local_path}${octopus_agent_file}"
echo ""
if [[ ! -s "${default_octopus_agent_local_path}${octopus_agent_file}" ]]; then
echo ""
echo "[sync_octopus_agent] - ERROR download file ${octopus_agent_url}/${octopus_agent_file} !"
echo ""
return 233
fi
done
echo "[sync_octopus_agent] - check for octopus agent download .."
echo ""
ls ${default_octopus_agent_local_path}
echo ""
echo ""
}
sync_octopus_agent_config() {
local octopus_agent_config_html="octopus_agent_config.html"
rm -rf ${octopus_agent_config_html}
wget "$agent_config_url/" -qO ${octopus_agent_config_html}
if [[ ! -s $octopus_agent_config_html ]]; then
echo "[sync_octopus_agent_config] - download agent config file error ! return false !"
return 233
fi
echo "清除旧的Agnet Config内容"
rm -rf $default_octopus_agent_config_local_path
mkdir -p ${default_octopus_agent_config_local_path}
echo ""
echo "开始同步最新版本的Octopus Agent Config !"
local octopus_agent_config_file_list=""
# shellcheck disable=SC2034
octopus_agent_config_file_list=$(cat ${octopus_agent_config_html} | grep -v h1 | grep "a href=" | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | tr "\n" " ")
local octopus_agent_config_list
IFS=" " read -ra octopus_agent_config_list <<<"$octopus_agent_config_file_list"
echo ""
local octopus_agent_config_file
for octopus_agent_config_file in "${octopus_agent_config_list[@]}"; do
echo "[sync_octopus_agent_config] => start to download => ${agent_config_url}/${octopus_agent_config_file}"
wget "${agent_config_url}/${octopus_agent_config_file}" -qO "${default_octopus_agent_config_local_path}${octopus_agent_config_file}"
echo ""
if [[ ! -s "${default_octopus_agent_config_local_path}${octopus_agent_config_file}" ]]; then
echo ""
echo "[sync_octopus_agent_config] - ERROR download file ${agent_config_url}/${octopus_agent_config_file} !"
echo ""
return 233
fi
done
echo "[sync_octopus_agent_config] - check for octopus agent config download .."
echo ""
ls ${default_octopus_agent_config_local_path}
echo ""
echo ""
}
sync_octopus_agent_version() {
# scp -P 22333 root@146.56.159.175:/data/
rm -rf ${default_octopus_agent_version_local_path}
curl -s -timeout=5 "${agent_version_url}" >${default_octopus_agent_version_local_path}
echo "[sync_octopus_agent_version] - agent latest version is => $(cat $default_octopus_agent_version_local_path)"
echo ""
}
sync_octopus_offline_nginx_proxy_conf() {
# 检查服务是否存在
if ! systemctl list-units --type service --all | grep -q "nginx.service"; then
echo "nginx 未安装! "
return 233
fi
local local_octopus_nginx_proxy_conf_path=/etc/nginx/conf.d/octopus-offline-nginx.conf
rm -rf ${local_octopus_nginx_proxy_conf_path}
wget ${agent_offline_proxy_conf} -qO ${local_octopus_nginx_proxy_conf_path}
if [[ ! -f "${local_octopus_nginx_proxy_conf_path}" ]]; then
echo ""
echo "[sync_octopus_offline_nginx_proxy_conf] - ERROR download file ${agent_offline_proxy_conf} !"
echo ""
return 233
fi
echo "[sync_octopus_offline_nginx_proxy_conf] - nginx offline sync has been synchronized !"
systemctl restart nginx
}
main() {
sync_octopus_agent
sync_octopus_agent_config
sync_octopus_agent_version
sync_octopus_offline_nginx_proxy_conf
}
main

View File

@@ -0,0 +1,26 @@
#!/bin/bash
target_minio="http://42.192.52.227:9000"
local_minio="http://localhost:9000"
minio_user_name="cmii"
minio_user_pass="B#923fC7mk"
bucket_name="octopus"
main() {
# alies
# mc alias set local ${local_minio} ${minio_user_name} ${minio_user_pass}
# mc alias set public ${target_minio} ${minio_user_name} ${minio_user_pass}
mc mb public/${bucket_name}
echo ""
# ls
local file
for file in $(mc ls local/${bucket_name}/ | awk '{print$6}'); do
echo "the current file is ${file}"
mc cp local/$bucket_name/"$file" public/$bucket_name/"$file"
done
}
main

View File

@@ -118,7 +118,7 @@ public class OMessageHandler {
); );
log.info( log.info(
"接收到的 matchKey为 {}\n, 结果为 [{}] \n内容为: {}\n ", "接收到的 matchKey为 {}, 结果为 [{}] 内容为: {}\n ",
matchKey, matchKey,
replayOMessage.getResultCode(), replayOMessage.getResultCode(),
replayOMessage.getResult() replayOMessage.getResult()

View File

@@ -43,8 +43,9 @@ public class TestImageSyncScheduler {
ArrayList<String> ImageFullNameList = new ArrayList<>(List.of( ArrayList<String> ImageFullNameList = new ArrayList<>(List.of(
// "harbor.cdcyy.com.cn/cmii/cmii-live-operator:5.2.0", // "harbor.cdcyy.com.cn/cmii/cmii-live-operator:5.2.0",
// "harbor.cdcyy.com.cn/cmii/cmii-srs-oss-adaptor:2023-SA" // "harbor.cdcyy.com.cn/cmii/cmii/srs:v5.0.195"
"harbor.cdcyy.com.cn/cmii/cmii-uav-process:5.4.0-040901" // "harbor.cdcyy.com.cn/cmii/cmii-uav-industrial-portfolio:5.4.9-cqly-040901",
"harbor.cdcyy.com.cn/cmii/cmii-uav-platform:5.3.0-cqly-040902"
)); ));
Boolean downloadAndCompressOnly = false; Boolean downloadAndCompressOnly = false;