[agent] bug fix
This commit is contained in:
@@ -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 <<EOF
|
||||
|
||||
Octopus Agent 没有安装! 请执行 --agent-install 命令进行安装
|
||||
|
||||
EOF
|
||||
return 2
|
||||
else
|
||||
# 关闭服务
|
||||
log "开始关闭OctopusAgent的服务!"
|
||||
systemctl stop octopus-agent.service
|
||||
sleep 2
|
||||
fi
|
||||
|
||||
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}"
|
||||
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 <<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:
|
||||
@@ -968,6 +1119,7 @@ help() {
|
||||
-h, --help 打印本说明文档
|
||||
--firewall 关闭防火墙
|
||||
--swap 关闭Swap
|
||||
--url 脚本的OSS URL地址
|
||||
--tools 安装通用的实用工具
|
||||
--docker <version> 安装docker 版本<version>
|
||||
--docker-compose 安装docker-compose 2.18.0
|
||||
@@ -979,63 +1131,13 @@ help() {
|
||||
--ssh-port <port> 修改ssh的登录端口 端口 <port>
|
||||
|
||||
--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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user