fix: use python script for downgrade to avoid heredoc issues
Downgrade New Runners to v0.2.6 / downgrade (push) Failing after 1s
Downgrade New Runners to v0.2.6 / downgrade (push) Failing after 1s
This commit is contained in:
@@ -13,6 +13,5 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Downgrade all runners on new server to v0.2.6
|
||||
run: |
|
||||
bash scripts/downgrade_runners_v026.sh
|
||||
- name: Downgrade all runners to v0.2.6 host mode
|
||||
run: python3 scripts/downgrade_v026.py
|
||||
|
||||
Executable
+6432
File diff suppressed because it is too large
Load Diff
Executable
+117
@@ -0,0 +1,117 @@
|
||||
#!/usr/bin/env python3
|
||||
"""将新服务器Runner全部降级为v0.2.6 host模式"""
|
||||
import base64
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
NEW_SERVER = "172.30.18.199"
|
||||
KEY_B64 = "b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZWQyNTUxOQAAACD6GquAk5vBEfbtaJCTSfnQEhjzC8e5GF60hSbPP0BJbAAAAJiQxGNokMRjaAAAAAtzc2gtZWQyNTUxOQAAACD6GquAk5vBEfbtaJCTSfnQEhjzC8e5GF60hSbPP0BJbAAAAED2muzuU4BAiCqbg0ayGxgiDvfS/xI1SFvb32oLzTnn8/oaq4CTm8ER9u1okJNJ+dASGPMLx7kYXrSFJs8/QElsAAAAFHJ1bm5lci1hZG1pbkB4aWFveGlhAQ=="
|
||||
REG_TOKEN = "ZMFH02WcdElay5ATmhhQYe1WNTESO9XMXcF0H9Tj"
|
||||
GITEA_URL = "https://git.xiaoxiajianji.com"
|
||||
LABELS = "saas,runtime-builder,host,ubuntu-latest,ubuntu-22.04"
|
||||
|
||||
# 写入密钥
|
||||
key_path = "/tmp/new_server_ed25519"
|
||||
with open(key_path, "wb") as f:
|
||||
f.write(base64.b64decode(KEY_B64))
|
||||
import os
|
||||
os.chmod(key_path, 0o600)
|
||||
|
||||
def ssh(cmd):
|
||||
"""执行SSH命令,返回输出"""
|
||||
full_cmd = f'ssh -i {key_path} -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@{NEW_SERVER} "{cmd}"'
|
||||
print(f"\n$ {cmd[:80]}...")
|
||||
result = subprocess.run(full_cmd, shell=True, capture_output=True, text=True)
|
||||
if result.stdout:
|
||||
print(result.stdout.strip())
|
||||
if result.stderr:
|
||||
print("STDERR:", result.stderr.strip()[:200])
|
||||
if result.returncode != 0:
|
||||
print(f" [RC={result.returncode}]")
|
||||
return result
|
||||
|
||||
def ssh_check(cmd):
|
||||
"""执行SSH命令,失败则退出"""
|
||||
r = ssh(cmd)
|
||||
if r.returncode != 0:
|
||||
print(f"命令失败,退出")
|
||||
sys.exit(1)
|
||||
return r
|
||||
|
||||
print("=" * 60)
|
||||
print("步骤1: 停止所有现有Runner服务和进程")
|
||||
print("=" * 60)
|
||||
ssh("systemctl stop gitea-runner-1.service gitea-runner-2.service gitea-runner-3.service gitea-runner-4.service gitea-runner-5.service gitea-runner-6.service 2>/dev/null; systemctl disable gitea-runner-1.service gitea-runner-2.service gitea-runner-3.service gitea-runner-4.service gitea-runner-5.service gitea-runner-6.service 2>/dev/null; pkill -f act_runner 2>/dev/null; sleep 1; echo 'done'")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤2: 备份现有配置")
|
||||
print("=" * 60)
|
||||
ssh_check("cp -r /opt/act-runner /opt/act-runner-backup-$(date +%Y%m%d%H%M) && echo backup_ok")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤3: 下载v0.2.6 act_runner")
|
||||
print("=" * 60)
|
||||
ssh_check("cd /opt/act-runner && curl -sL -o act_runner_v0.2.6 https://gitea.com/gitea/act_runner/releases/download/v0.2.6/act_runner-0.2.6-linux-amd64 && chmod +x act_runner_v0.2.6 && ./act_runner_v0.2.6 --version")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤4: 注册6个仓库级Runner (host模式)")
|
||||
print("=" * 60)
|
||||
for i in range(1, 7):
|
||||
print(f"\n--- 注册 Runner {i} ---")
|
||||
cmd = f"""
|
||||
mkdir -p /opt/act-runner/runner-{i}
|
||||
cd /opt/act-runner/runner-{i}
|
||||
rm -f .runner config.yaml 2>/dev/null
|
||||
/opt/act-runner/act_runner_v0.2.6 register \
|
||||
--instance {GITEA_URL} \
|
||||
--token {REG_TOKEN} \
|
||||
--name xiaoxia-ci-runner-new-{i} \
|
||||
--labels {LABELS} \
|
||||
--no-interactive 2>&1
|
||||
echo '---注册完成---'
|
||||
"""
|
||||
ssh(cmd.strip())
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤5: 创建systemd服务")
|
||||
print("=" * 60)
|
||||
for i in range(1, 7):
|
||||
service_file = f"/etc/systemd/system/act-runner-{i}.service"
|
||||
service_content = f"""[Unit]
|
||||
Description=Gitea Act Runner {i}
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/act-runner/runner-{i}
|
||||
ExecStart=/opt/act-runner/act_runner_v0.2.6 daemon
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
"""
|
||||
# 用base64传内容避免转义问题
|
||||
content_b64 = base64.b64encode(service_content.encode()).decode()
|
||||
ssh(f"echo {content_b64} | base64 -d > {service_file} && echo service_{i}_ok")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("步骤6: 启动所有Runner")
|
||||
print("=" * 60)
|
||||
start_cmd = """
|
||||
systemctl daemon-reload
|
||||
for i in 1 2 3 4 5 6; do
|
||||
systemctl enable act-runner-$i.service
|
||||
systemctl start act-runner-$i.service
|
||||
echo "act-runner-$i: $(systemctl is-active act-runner-$i.service)"
|
||||
done
|
||||
sleep 3
|
||||
echo "进程数: $(ps aux | grep act_runner_v0.2.6 | grep -v grep | wc -l)"
|
||||
ps aux | grep act_runner_v0.2.6 | grep -v grep
|
||||
"""
|
||||
ssh(start_cmd.strip())
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("全部完成!")
|
||||
print("=" * 60)
|
||||
Reference in New Issue
Block a user