35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
"""看 worker 启动日志 + Traceback 完整内容"""
|
|
import os, paramiko
|
|
|
|
PASS = os.environ.get("REMOTE_PASS", "")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("207.57.129.228", port=19717, username="root", password=PASS,
|
|
timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
|
|
def run(label, cmd, timeout=30):
|
|
print(f"\n=== {label} ===")
|
|
si, so, se = c.exec_command(cmd, timeout=timeout)
|
|
out = so.read().decode(errors="replace")
|
|
err = se.read().decode(errors="replace")
|
|
print(out.rstrip())
|
|
if err.strip():
|
|
print(f"[stderr] {err.rstrip()}")
|
|
|
|
|
|
# 1) worker 启动时全部 INFO/ERROR 日志(关键!)
|
|
run("1) worker 启动日志(前 60 行)", "bash -lc 'cd /srv/news && docker compose logs worker 2>&1 | head -60'")
|
|
|
|
# 2) Traceback 完整内容
|
|
run("2) Traceback 完整内容", "bash -lc 'cd /srv/news && docker compose logs worker 2>&1 | grep -A 25 Traceback | head -100'")
|
|
|
|
# 3) container 启动时间 + restart count
|
|
run("3) container 启动时间 + restart count",
|
|
"docker inspect news-aggregator-worker-1 --format '{{.State.StartedAt}} restarts={{.RestartCount}} status={{.State.Status}}'")
|
|
|
|
# 4) 服务器当前时间
|
|
run("4) 服务器当前时间", "date '+%Y-%m-%d %H:%M:%S'")
|
|
|
|
c.close()
|