v5: use huawei mirror, add git install, longer timeouts
This commit is contained in:
@@ -20,25 +20,27 @@ with open(key_path, "w") as f:
|
||||
f.write(KEY_CONTENT)
|
||||
os.chmod(key_path, 0o600)
|
||||
|
||||
def ssh(cmd, timeout=600):
|
||||
def ssh(cmd, timeout=1800):
|
||||
full_cmd = f'ssh -i {key_path} -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o ServerAliveInterval=60 root@{NEW_SERVER} "{cmd}"'
|
||||
print(f"\n$ {cmd[:120]}")
|
||||
sys.stdout.flush()
|
||||
result = subprocess.run(full_cmd, shell=True, capture_output=True, text=True, timeout=timeout)
|
||||
if result.stdout:
|
||||
lines = result.stdout.strip().split('\n')
|
||||
for line in lines[:20]:
|
||||
for line in lines[:30]:
|
||||
print(" ", line[:200])
|
||||
if len(lines) > 20:
|
||||
print(f" ... ({len(lines)-20} more lines)")
|
||||
if len(lines) > 30:
|
||||
print(f" ... ({len(lines)-30} more lines)")
|
||||
if result.stderr:
|
||||
err_lines = result.stderr.strip().split('\n')
|
||||
for line in err_lines[:10]:
|
||||
if "Warning" not in line and "Connection reset" not in line:
|
||||
for line in err_lines[:15]:
|
||||
if "Warning" not in line and "Connection reset" not in line and "Permanently added" not in line:
|
||||
print(" ERR:", line[:200])
|
||||
print(f" [RC={result.returncode}]")
|
||||
sys.stdout.flush()
|
||||
return result
|
||||
|
||||
def ssh_check(cmd, timeout=600):
|
||||
def ssh_check(cmd, timeout=1800):
|
||||
r = ssh(cmd, timeout)
|
||||
if r.returncode != 0:
|
||||
print(f"命令失败,退出: {cmd[:80]}")
|
||||
@@ -48,7 +50,7 @@ def ssh_check(cmd, timeout=600):
|
||||
print("=" * 60)
|
||||
print("步骤0: 检查当前Python版本")
|
||||
print("=" * 60)
|
||||
r = ssh("python3 --version 2>&1; which python3; pip3 --version 2>&1 || true")
|
||||
r = ssh("export PATH=/usr/local/bin:$PATH && python3 --version 2>&1; which python3; pip3 --version 2>&1 || true")
|
||||
if "Python 3.10" in r.stdout or "Python 3.10" in r.stderr:
|
||||
print("Python 3.10 已安装,跳过编译")
|
||||
skip_build = True
|
||||
@@ -59,19 +61,21 @@ if not skip_build:
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤1: 安装编译依赖")
|
||||
print("=" * 60)
|
||||
ssh_check("yum install -y gcc gcc-c++ make openssl-devel bzip2-devel libffi-devel zlib-devel readline-devel sqlite-devel wget 2>&1 | tail -5", timeout=300)
|
||||
ssh_check("yum install -y gcc gcc-c++ make openssl-devel bzip2-devel libffi-devel zlib-devel readline-devel sqlite-devel wget 2>&1 | tail -3", timeout=300)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤2: 下载Python 3.10.14源码")
|
||||
print("步骤2: 下载Python 3.10.14源码(国内镜像)")
|
||||
print("=" * 60)
|
||||
ssh_check("cd /tmp && wget -q https://www.python.org/ftp/python/3.10.14/Python-3.10.14.tgz && echo download_ok", timeout=120)
|
||||
# 用华为云镜像,速度快
|
||||
ssh_check("cd /tmp && wget -q --timeout=60 --tries=3 https://mirrors.huaweicloud.com/python/3.10.14/Python-3.10.14.tgz && echo download_ok || (echo 'huawei mirror failed, trying npmmirror...' && wget -q --timeout=60 --tries=3 https://npmmirror.com/mirrors/python/3.10.14/Python-3.10.14.tgz && echo download_ok)", timeout=300)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤3: 解压并编译安装(约5-10分钟)")
|
||||
print("=" * 60)
|
||||
ssh_check("cd /tmp && tar xzf Python-3.10.14.tgz && cd Python-3.10.14 && ./configure --prefix=/usr/local --enable-optimizations --with-ensurepip=install 2>&1 | tail -5", timeout=120)
|
||||
# make -j$(nproc) 编译
|
||||
ssh_check("cd /tmp/Python-3.10.14 && make -j$(nproc) 2>&1 | tail -10", timeout=600)
|
||||
ssh_check("cd /tmp && rm -rf Python-3.10.14 && tar xzf Python-3.10.14.tgz && echo extract_ok", timeout=60)
|
||||
ssh_check("cd /tmp/Python-3.10.14 && ./configure --prefix=/usr/local --with-ensurepip=install 2>&1 | tail -5", timeout=180)
|
||||
# 不用 --enable-optimizations 加快编译速度
|
||||
ssh_check("cd /tmp/Python-3.10.14 && make -j$(nproc) 2>&1 | tail -5", timeout=1200)
|
||||
ssh_check("cd /tmp/Python-3.10.14 && make altinstall 2>&1 | tail -5", timeout=300)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
@@ -87,29 +91,33 @@ ssh_check("export PATH=/usr/local/bin:$PATH && python3 --version && pip3 --versi
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤6: 修复CMD Agent端口 5000 -> 5927")
|
||||
print("=" * 60)
|
||||
# 检查server.py中的端口配置
|
||||
ssh("grep -n 'port\\|PORT\\|5000\\|5927' /opt/cmd-agent/server.py 2>&1 | head -10")
|
||||
# 替换端口
|
||||
ssh("sed -i 's/port=5000/port=5927/g; s/port = 5000/port = 5927/g; s/5000/5927/g' /opt/cmd-agent/server.py 2>&1 && echo port_fixed || true")
|
||||
ssh("grep -n '5927\\|5000' /opt/cmd-agent/systemd/cmd-agent.service 2>/dev/null || echo 'no service file found'")
|
||||
# 重启CMD Agent
|
||||
ssh("systemctl restart cmd-agent 2>&1 && sleep 2 && systemctl status cmd-agent 2>&1 | head -5")
|
||||
ssh("grep -n 'port\\|PORT\\|5000\\|5927' /opt/cmd-agent/server.py 2>&1 | head -10 || echo 'no port found in server.py'")
|
||||
ssh("cd /opt/cmd-agent && sed -i 's/port=5000/port=5927/g; s/port = 5000/port = 5927/g; s/\"5000\"/\"5927\"/g' server.py 2>&1 && echo sed_done || true")
|
||||
# 检查systemd服务文件
|
||||
ssh("find /etc/systemd -name 'cmd-agent*' 2>/dev/null; systemctl cat cmd-agent 2>&1 | head -20 || true")
|
||||
ssh("systemctl daemon-reload && systemctl restart cmd-agent 2>&1 && sleep 2 && systemctl is-active cmd-agent")
|
||||
# 验证端口
|
||||
ssh("ss -tlnp 2>/dev/null | grep 5927 || netstat -tlnp 2>/dev/null | grep 5927 || echo 'checking port...'")
|
||||
ssh("ss -tlnp 2>/dev/null | grep -E '5927|5000' || netstat -tlnp 2>/dev/null | grep -E '5927|5000' || echo 'port check done'")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤7: 重启6个Runner服务让新Python生效")
|
||||
print("步骤7: 安装git(新Runner需要git才能checkout)")
|
||||
print("=" * 60)
|
||||
for i in range(1, 7):
|
||||
ssh(f"systemctl restart act-runner-{i}.service 2>&1 && echo runner-{i}_restarted || systemctl restart gitea-runner-{i}.service 2>&1 && echo runner-{i}_restarted_old || true")
|
||||
ssh_check("which git 2>&1 || yum install -y git 2>&1 | tail -3", timeout=120)
|
||||
ssh("git --version 2>&1")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤8: 最终验证")
|
||||
print("步骤8: 重启6个Runner服务让新Python生效")
|
||||
print("=" * 60)
|
||||
ssh("for i in 1 2 3 4 5 6; do systemctl restart act-runner-$i.service 2>/dev/null && echo runner-$i\_restarted || systemctl restart gitea-runner-$i.service 2>/dev/null && echo runner-$i\_restarted_old || echo runner-$i\_notfound; done")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤9: 最终验证")
|
||||
print("=" * 60)
|
||||
ssh("echo '--- Python ---' && export PATH=/usr/local/bin:$PATH && python3 --version && pip3 --version")
|
||||
ssh("echo '--- Git ---' && git --version")
|
||||
ssh("echo '--- Runners ---' && systemctl list-units 'act-runner-*' --no-legend 2>/dev/null | head -10 || systemctl list-units 'gitea-runner-*' --no-legend 2>/dev/null | head -10")
|
||||
ssh("echo '--- CMD Agent ---' && systemctl status cmd-agent 2>&1 | head -3")
|
||||
ssh("echo '--- Port 5927 ---' && (ss -tlnp 2>/dev/null | grep 5927 || netstat -tlnp 2>/dev/null | grep 5927 || echo 'port check done')")
|
||||
ssh("echo '--- Port 5927 ---' && (ss -tlnp 2>/dev/null | grep 5927 || netstat -tlnp 2>/dev/null | grep 5927 || echo 'port 5927 not listening')")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("全部完成!")
|
||||
|
||||
Reference in New Issue
Block a user