[init] 增加octopus agent的部分

This commit is contained in:
zeaslity
2023-10-16 18:07:12 +08:00
parent a564bafc2d
commit 3b30f5eee1
3 changed files with 181 additions and 28 deletions

View File

@@ -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 <<EOF
[Unit]
Description=Octopus Agent Service
Documentation=https://octopus.107421.xyz/
After=syslog.target network.target
[Service]
SuccessExitStatus=143
SyslogIdentifier=octopus-agent
User=root
Type=simple
WorkingDirectory=/octopus-agent
ExecStart=/octopus-agent/octopus-agent -agentServerInfoConf=/octopus-agent/octopus-agent.conf -version=shanghai
ExecStop=/bin/kill -15 \$MAINPID
[Install]
WantedBy=multi-user.target
EOF
colorEchoBlue "开始配置Agent日志输出文件"
# https://www.benzhu.xyz/linux12/
cat >/etc/rsyslog.d/octopus-agent.conf <<EOF
if \$programname == 'octopus-agent' then /var/log/octopus-agent.log
& stop
EOF
rsyslogd -N1 -f /etc/rsyslog.d/octopus-agent.conf
systemctl restart rsyslog
FunctionEnd
}
install_octopus_agent(){
FunctionStart "安装 Octopus Agent"
colorEchoBlue "开始检查最新的版本!"
local latest_version=$(curl $octopus_agent_url | grep -v h1 | grep "a href=" | head -1 | awk '{print$2}' | cut -d">" -f2 | cut -d"<" -f1 | cut -d"_" -f4-)
log "查询得到的Octopus Agent的最新版本为 => ${latest_version}"
SplitBlue
# Agent二进制文件的命名规则为 octopus-agent_linux_amd64_<version>
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 <<EOF
查看Octopus Agent的运行日志 👇
tail -f -n 1500 /var/log/octopus-agent.log
journalctl -u octopus-agent.service -n 200 -f
----------------------------
查看 Octopus Agent的运行状态 systemctl status octopus-agent.service -l
EOF
FunctionEnd
}
#######################################
# description
# Arguments:
@@ -781,6 +909,9 @@ help() {
# 不安装docker的初始化
$base_init_command --cn
# 启动 Octopus Agent
$base_init_command --agent-install
-h, --help 打印本说明文档
--firewall 关闭防火墙
--swap 关闭Swap
@@ -794,6 +925,9 @@ help() {
--ssh-login 修改ssh的登录密钥
--ssh-port <port> 修改ssh的登录端口 端口 <port>
--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时间同步--包含下面的设置