nomadro/deploy/work/_fix_work_env_us.py
Eric ffa456afdf Ship social join profile + SeaweedFS avatars, notify/coffee, and .com audience stack.
Pay-then-profile join desk with live card, S3 upload fallback, hydration-safe drafts; document on test9 README.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 02:25:05 +08:00

77 lines
2.6 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Ensure WORK_API_URL reaches Next on US and re-smoke /api/work/v1."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
US = ("108.174.50.68", "root", "Xiao4669805")
REMOTE = r"""
set -euo pipefail
mkdir -p /etc/systemd/system/nomadro.service.d /etc/nomadro
grep -q '^WORK_API_URL=' /etc/nomadro/portal.env 2>/dev/null \
&& sed -i 's|^WORK_API_URL=.*|WORK_API_URL=http://127.0.0.1:8021|' /etc/nomadro/portal.env \
|| echo 'WORK_API_URL=http://127.0.0.1:8021' >> /etc/nomadro/portal.env
cat >/etc/systemd/system/nomadro.service.d/work-api.conf <<'EOF'
[Service]
EnvironmentFile=-/etc/nomadro/portal.env
Environment=WORK_API_URL=http://127.0.0.1:8021
EOF
systemctl daemon-reload
systemctl restart nomadro-work || true
sleep 3
systemctl is-active nomadro-work || true
curl -sS -m 5 http://127.0.0.1:8021/health || true
echo
systemctl kill -s9 nomadro.service 2>/dev/null || true
fuser -k 4003/tcp 2>/dev/null || true
sleep 1
systemctl reset-failed nomadro || true
systemctl start nomadro
sleep 7
systemctl is-active nomadro || true
pid=$(systemctl show -p MainPID --value nomadro)
echo PID=$pid
tr '\0' '\n' < /proc/$pid/environ 2>/dev/null | grep -E '^WORK_' || echo NO_WORK_ENV_PARENT
# next may spawn child — check children too
for p in $(pgrep -P "$pid" 2>/dev/null); do
echo child=$p
tr '\0' '\n' < /proc/$p/environ 2>/dev/null | grep -E '^WORK_' || true
done
curl -sS -m 5 http://127.0.0.1:8021/api/work/v1/health || true
echo
curl -sS -m 12 -o /dev/null -w 'api_boards=%{http_code}\n' https://nomadro.com/api/work/v1/boards || true
curl -sS -m 12 https://nomadro.com/api/work/v1/boards | head -c 320; echo
curl -sS -m 8 -o /dev/null -w 'api_health=%{http_code}\n' https://nomadro.com/api/work/v1/health || true
curl -sS -m 8 -o /dev/null -w 'work=%{http_code}\n' https://nomadro.com/social/work || true
"""
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
h, u, p = US
c.connect(h, 22, u, p, timeout=40, allow_agent=False, look_for_keys=False)
try:
_, o, e = c.exec_command(REMOTE, timeout=120)
out = o.read().decode("utf-8", "replace")
err = e.read().decode("utf-8", "replace")
code = o.channel.recv_exit_status()
print(out)
if err.strip():
print("STDERR", err[-1500:])
print("exit", code)
return code
finally:
c.close()
if __name__ == "__main__":
raise SystemExit(main())