26 lines
920 B
Python
26 lines
920 B
Python
"""分步调试 - 修 psql 调用的 env"""
|
|
import os, paramiko
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("207.57.129.228", port=19717, username="root",
|
|
password=os.environ["REMOTE_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")
|
|
rc = so.channel.recv_exit_status()
|
|
if out.strip(): print(out.rstrip())
|
|
if err.strip(): print(f"[stderr] {err.rstrip()}")
|
|
print(f"-> rc={rc}")
|
|
|
|
|
|
# psql 走 docker compose exec(自动加载 .env 的 env_file)
|
|
run("step 4 fix: 用 docker compose exec",
|
|
"bash -lc 'cd /srv/news && docker compose exec -T postgres psql -U $POSTGRES_USER -d $POSTGRES_DB -f /tmp/diag.sql'")
|
|
|
|
c.close()
|