From 3b30f5eee152ce5970214539cd2d0e5a94f047c0 Mon Sep 17 00:00:00 2001 From: zeaslity Date: Mon, 16 Oct 2023 18:07:12 +0800 Subject: [PATCH] =?UTF-8?q?[init]=20=E5=A2=9E=E5=8A=A0octopus=20agent?= =?UTF-8?q?=E7=9A=84=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Public/init-script-wdd.sh | 172 +++++++++++++++++++++++++++++++++--- Public/lib/wdd-lib-clean.sh | 3 + Public/lib/wdd-lib-sys.sh | 34 +++---- 3 files changed, 181 insertions(+), 28 deletions(-) diff --git a/Public/init-script-wdd.sh b/Public/init-script-wdd.sh index f2cd1d0..1668643 100644 --- a/Public/init-script-wdd.sh +++ b/Public/init-script-wdd.sh @@ -4,27 +4,29 @@ # set -o nounset # set -o pipefail +docker_version=20.10.10 +oss_url_prefix="https://oss-s1.107421.xyz" +modify_ssh_port=22333 +octopus_agent_path=/usr/local/etc/octpus-agent/ +octopus_agent_url=https://happybirthday.107421.xyz/octopus-agent/ + echo "" echo "" -mkdir -p /root/wdd/lib/ +mkdir -p ${octopus_agent_path}/lib/ lib_file_list=(wdd-lib-log.sh wdd-lib-sys.sh) for lib_file in ${lib_file_list[@]}; do - wget "https://oss-s1.107421.xyz/${lib_file}" -qO "/root/wdd/lib/${lib_file}" - echo "加载库文件 < /root/wdd/lib/${lib_file}" - . "/root/wdd/lib/${lib_file}" + wget "${oss_url_prefix}/${lib_file}" -qO "${octopus_agent_path}/lib/${lib_file}" + echo "加载库文件 < ${octopus_agent_path}/lib/${lib_file}" + . "${octopus_agent_path}/lib/${lib_file}" done # debug #lib_file_list=(wdd-lib-sys.sh wdd-lib-log.sh ) #for lib_file in ${lib_file_list[@]} ; do -# echo "加载库文件 < /root/wdd/lib/${lib_file}" -# . "/root/wdd/lib/${lib_file}" +# echo "加载库文件 < ${octopus_agent_path}/lib/${lib_file}" +# . "${octopus_agent_path}/lib/${lib_file}" #done -docker_version=20.10.10 -oss_url_prefix="https://oss-s1.107421.xyz" -modify_ssh_port=22333 - # 脚本执行内容 deploy_in_cn=0 is_shutdown_firewall=0 @@ -36,6 +38,8 @@ 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 # 脚本执行内容 ## 安装所需要的程序,及依赖程序 @@ -754,6 +758,130 @@ common_tool_install() { FunctionEnd } +remove_octopus_agent(){ + + FunctionStart "清理Octopus Agent" + + if not systemctl status octopus-agent.service; then + log "octopus agent 没有安装! 直接返回" + return 0 + fi + + # 关闭服务 + systemctl stop octopus-agent.service + sleep 2 + SplitLine + systemctl disable octopus-agent.service + SplitLine + rm -rf /etc/systemd/system/octopus-agent.service + sleep 1 + systemctl daemon-reload + # 删除残留 + SplitLine + rm -rf ${octopus_agent_path} + FunctionEnd + +} +daemon_octopus_agent(){ + # https://www.baeldung.com/linux/run-java-application-as-service + FunctionStart "[守护]-开始设置Agent的守护进程" + + cat >/etc/systemd/system/octopus-agent.service </etc/rsyslog.d/octopus-agent.conf <" -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}" + SplieGreen + cp "$agent_latest_version" octopus-agent + chmod +x octopus-agent + echo "" + colorEchoBlue "---------------- ls the ${octopus_agent_path} ----------------------" + ls ${octopus_agent_path} | grep octopus-agent + echo "" + + log "开始下载 Octopus Agent Config !" + wget "${oss_url_prefix}/octopus-agent.yaml" -qO "${octopus_agent_path}octopus-agent.yaml" + echo "" + colorEchoBlue "---------------- ls the ${octopus_agent_path} ----------------------" + ls ${octopus_agent_path} | grep ".yaml" + echo "" + + log "开始配置Agent启动的基础环境信息" + rm -rf "$octopus_agent_path/lib/wdd-lib-env.sh" + wget "${oss_url_prefix}/wdd-lib-env.sh" -qO "${octopus_agent_path}/lib/wdd-lib-env.sh" + SplitGreen + log "开始手机Agent主机的信息!" + echo "" + ${octopus_agent_path}/lib/wdd-lib-env.sh + echo "" + SplitGreen + + daemon_octopus_agent + + log "开始启动 Octopus Agent!" + + systemctl daemon-reload + sleep 1 + systemctl enable octopus-agent.service + systemctl restart octopus-agent.service + + cat - 1>&2 < 修改ssh的登录端口 端口 + --agent-install 安装 Octopus-Agent + --agent-remove 卸载 Octopus-Agent + EOF } @@ -837,6 +971,12 @@ while [[ $# -gt 0 ]]; do is_modify_ssh_port=1 modify_ssh_port=$2 ;; + --agent-install) + is_install_agent=1 + ;; + --agent-remove) + is_remove_agent=1 + ;; *) # unknown option ;; @@ -902,9 +1042,19 @@ main() { change_docker_register_mirror fi + if [[ $is_install_agent -eq 1 ]]; then + # 安装agent + install_octopus_agent + fi + + if [[ $is_remove_agent -eq 1 ]]; then + # 卸载agent + remove_octopus_agent + fi + if [[ $is_install_zsh -eq 1 ]]; then # 安装宇宙第一shell的zsh - install_zsh + install_zsh fi # 使用chrony进行NTP时间同步--包含下面的设置 diff --git a/Public/lib/wdd-lib-clean.sh b/Public/lib/wdd-lib-clean.sh index 434e1f6..215f554 100644 --- a/Public/lib/wdd-lib-clean.sh +++ b/Public/lib/wdd-lib-clean.sh @@ -21,6 +21,9 @@ CleanOracleAgent() { done rm -rf /root/snap + rm -rf /var/snap + rm -rf /usr/bin/snap + rm -rf /snap/ FunctionSuccess FunctionEnd } diff --git a/Public/lib/wdd-lib-sys.sh b/Public/lib/wdd-lib-sys.sh index 07535e6..486b77f 100644 --- a/Public/lib/wdd-lib-sys.sh +++ b/Public/lib/wdd-lib-sys.sh @@ -8,8 +8,8 @@ fi # 系统相关 -LinuxReleaseVersion="" -LinuxRelease="" +linux_release_version="" +linux_release="" OS_BIT="" CMD_INSTALL="apt-get -y -qq install" CMD_UPDATE="apt-get -qq update" @@ -47,23 +47,23 @@ check_sys() { case $sys_bit in i[36]86) OS_BIT="32" - LinuxRelease="386" + linux_release="386" ;; x86_64) OS_BIT="64" - LinuxRelease="amd64" + linux_release="amd64" ;; *armv6*) OS_BIT="arm" - LinuxRelease="arm6" + linux_release="arm6" ;; *armv7*) OS_BIT="arm" - LinuxRelease="arm7" + linux_release="arm7" ;; *aarch64* | *armv8*) OS_BIT="arm64" - LinuxRelease="arm64" + linux_release="arm64" ;; *) error " @@ -72,27 +72,27 @@ check_sys() { " && exit 1 ;; esac - log "获取的系统信息如下: OS_BIT => ${OS_BIT} LinuxRelease => $LinuxRelease" + log "获取的系统信息如下: OS_BIT => ${OS_BIT} LinuxRelease => $linux_release" ## 判定Linux的发行版本 if [ -f /etc/redhat-release ]; then - LinuxReleaseVersion="centos" + linux_release_version="centos" elif cat /etc/issue | grep -Eqi "debian"; then - LinuxReleaseVersion="debian" + linux_release_version="debian" elif cat /etc/issue | grep -Eqi "ubuntu"; then - LinuxReleaseVersion="ubuntu" + linux_release_version="ubuntu" elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then - LinuxReleaseVersion="centos" + linux_release_version="centos" elif cat /proc/version | grep -Eqi "debian"; then - LinuxReleaseVersion="debian" + linux_release_version="debian" elif cat /proc/version | grep -Eqi "ubuntu"; then - LinuxReleaseVersion="ubuntu" + linux_release_version="ubuntu" elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then - LinuxReleaseVersion="centos" + linux_release_version="centos" else - LinuxReleaseVersion="" + linux_release_version="" fi - log "系统参数信息如下: LinuxReleaseVersion => $LinuxReleaseVersion" + log "系统参数信息如下: LinuxReleaseVersion => $linux_release_version" # 判断系统的包管理工具 apt, yum, or zypper getPackageManageTool() {