From 57b95e361020801408e65bd86dd9972b0b7ec08c Mon Sep 17 00:00:00 2001 From: zeaslity Date: Thu, 23 Nov 2023 09:25:02 +0800 Subject: [PATCH] [agent] bug fix --- .idea/dataSources.local.xml | 2 +- Public/init-script-wdd.sh | 246 ++++++++++++++++++++++++++---------- Public/lib/wdd-lib-clean.sh | 8 ++ 3 files changed, 185 insertions(+), 71 deletions(-) diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index 44fd8ec..404a19d 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + #@ diff --git a/Public/init-script-wdd.sh b/Public/init-script-wdd.sh index 14a5a79..74d17c4 100644 --- a/Public/init-script-wdd.sh +++ b/Public/init-script-wdd.sh @@ -4,6 +4,7 @@ # set -o nounset # set -o pipefail + docker_version=20.10.10 oss_url_prefix="https://oss-s1.107421.xyz" modify_ssh_port=22333 @@ -11,6 +12,83 @@ octopus_agent_path=/usr/local/etc/octpus-agent octopus_agent_url=https://happybirthday.107421.xyz/octopus-agent agent_config_url=https://happybirthday.107421.xyz/agent-config +# 脚本执行内容 +deploy_in_cn=0 +is_shutdown_firewall=0 +is_disable_swap=0 +is_common_tool_install=0 +is_install_docker=0 +is_install_docker_compose=0 +is_install_zsh=0 +is_install_host=0 +is_modify_ssh_login=0 +is_modify_ssh_port=0 +is_install_agent=0 +is_update_agent=0 +is_remove_agent=0 +# 脚本执行内容 + +# read config +######################### +while [[ $# -gt 0 ]]; do + case "$1" in + -h | --help) + help + exit 0 + ;; + --cn) + deploy_in_cn=1 + ;; + --firewall) + is_shutdown_firewall=1 + ;; + --swap) + is_disable_swap=1 + ;; + --tools) + is_common_tool_install=1 + ;; + --docker) + is_install_docker=1 + docker_version="$2" + shift + ;; + --url) + oss_url_prefix="$2" + shift + ;; + --docker-compose) + is_install_docker_compose=1 + ;; + --zsh) + is_install_zsh=1 + ;; + --host) + is_install_host=1 + ;; + --ssh-login) + is_modify_ssh_login=1 + ;; + --ssh-port) + is_modify_ssh_port=1 + modify_ssh_port=$2 + ;; + --agent-install) + is_install_agent=1 + ;; + --agent-update) + is_update_agent=1 + ;; + --agent-remove) + is_remove_agent=1 + ;; + *) + # unknown option + ;; + esac + shift # past argument or value +done + echo "" echo "" mkdir -p ${octopus_agent_path}/lib/ @@ -28,20 +106,7 @@ done # . "${octopus_agent_path}/lib/${lib_file}" #done -# 脚本执行内容 -deploy_in_cn=0 -is_shutdown_firewall=0 -is_disable_swap=0 -is_common_tool_install=0 -is_install_docker=0 -is_install_docker_compose=0 -is_install_zsh=0 -is_install_host=0 -is_modify_ssh_login=0 -is_modify_ssh_port=0 -is_install_agent=0 -is_remove_agent=0 -# 脚本执行内容 + ## 安装所需要的程序,及依赖程序 install_demand_softwares() { @@ -935,6 +1000,92 @@ EOF FunctionEnd } +update_octopus_agent(){ + FunctionStart "更新 Octopus Agent" + + local systemd_config_path=("/lib/systemd/system/" "/etc/systemd/system/") + + local systemd_config_file + local agent_installed=0 + for systemd_config_file in ${systemd_config_path[@]}; do + if ls "${systemd_config_file}"* | grep -q octopus-agent.service; then + agent_installed=1 + fi + done + + if [[ $agent_installed -eq 0 ]]; then + log "octopus agent 没有安装! 关闭成功!" + cat - 1>&2 <" -f2 | cut -d"<" -f1 | cut -d"_" -f4-) + + log "查询得到的Octopus Agent的最新版本为 => ${latest_version}" + SplitBlue + # Agent二进制文件的命名规则为 octopus-agent_linux_amd64_ + local agent_latest_version="octopus-agent_linux_${linux_release}_${latest_version}" + colorEchoBlue "octopus agent latest version is => [ $agent_latest_version ]" + + log "开始下载最新版本的Octopus Agent !" + wget "${octopus_agent_url}/${agent_latest_version}" -qO "${octopus_agent_path}/${agent_latest_version}" + SplitGreen + cp "${octopus_agent_path}/$agent_latest_version" "${octopus_agent_path}/octopus-agent" + chmod +x "${octopus_agent_path}/octopus-agent" + echo "" + colorEchoBlue "---------------- ls the ${octopus_agent_path} ----------------------" + ls ${octopus_agent_path} | grep octopus-agent + echo "" + + log "开始下载 Octopus Agent Config !" + rm -rf index.html + + local agentConfigFileList=$(curl "$agent_config_url/" | grep -v h1 | grep "a href=" | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4- | tr "\n" " ") + + IFS=" " read -ra file_array <<<"$agentConfigFileList" + + local agent_config + for agent_config in "${file_array[@]}"; do + colorEchoBlue "agent config file is => $agent_config" + wget -q "$agent_config_url/$agent_config" -qO "${octopus_agent_path}/$agent_config" + echo "" + done + + colorEchoBlue "---------------- ls the ${octopus_agent_path} ----------------------" + ls ${octopus_agent_path} | grep ".yaml" + echo "" + + log "开始重启启动 Octopus Agent!" + + systemctl enable octopus-agent.service + systemctl start octopus-agent.service + + cat - 1>&2 < 安装docker 版本 --docker-compose 安装docker-compose 2.18.0 @@ -979,63 +1131,13 @@ help() { --ssh-port 修改ssh的登录端口 端口 --agent-install 安装 Octopus-Agent + --agent-install 更新 Octopus-Agent --agent-remove 卸载 Octopus-Agent EOF } -######################### -while [[ $# -gt 0 ]]; do - case "$1" in - -h | --help) - help - exit 0 - ;; - --cn) - deploy_in_cn=1 - ;; - --firewall) - is_shutdown_firewall=1 - ;; - --swap) - is_disable_swap=1 - ;; - --tools) - is_common_tool_install=1 - ;; - --docker) - is_install_docker=1 - docker_version="$2" - shift - ;; - --docker-compose) - is_install_docker_compose=1 - ;; - --zsh) - is_install_zsh=1 - ;; - --host) - is_install_host=1 - ;; - --ssh-login) - is_modify_ssh_login=1 - ;; - --ssh-port) - is_modify_ssh_port=1 - modify_ssh_port=$2 - ;; - --agent-install) - is_install_agent=1 - ;; - --agent-remove) - is_remove_agent=1 - ;; - *) - # unknown option - ;; - esac - shift # past argument or value -done + ####################################### # description @@ -1085,21 +1187,25 @@ main() { if [[ $is_install_docker -eq 1 ]]; then install_docker + if [[ $deploy_in_cn -eq 1 ]]; then + change_docker_register_mirror + fi fi if [[ $is_install_docker_compose -eq 1 ]]; then install_docker_compose fi - if [[ $deploy_in_cn -eq 1 ]]; then - change_docker_register_mirror - fi - if [[ $is_install_agent -eq 1 ]]; then # 安装agent install_octopus_agent fi + if [[ $is_update_agent -eq 1 ]]; then + # 安装agent + update_octopus_agent + fi + if [[ $is_remove_agent -eq 1 ]]; then # 卸载agent remove_octopus_agent diff --git a/Public/lib/wdd-lib-clean.sh b/Public/lib/wdd-lib-clean.sh index fac492b..e985d94 100644 --- a/Public/lib/wdd-lib-clean.sh +++ b/Public/lib/wdd-lib-clean.sh @@ -20,10 +20,18 @@ clean_oracle_agent() { systemctl disable $i done + local loop + for loop in $(df -h | grep snap | awk '{print$1}');do + echo "unmount $loop" + umount "$loop" + done + rm -rf /root/snap rm -rf /var/snap rm -rf /usr/bin/snap rm -rf /snap/ + rm -rf /var/lib/snapd + FunctionSuccess FunctionEnd }