81 lines
2.5 KiB
Bash
Executable file
81 lines
2.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
ssh -i /Users/user/.ssh/livingip_hetzner_20260604_ed25519 -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=10 root@77.42.65.182 "python3 -" <<'PY' | base64 | tr -d '\n'
|
|
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
repo = Path("/opt/teleo-eval/workspaces/deploy-infra")
|
|
packet_path = Path("/opt/teleo-eval/workspaces/deploy-infra/docs/reports/leo-working-state-20260709/telegram-visible-direct-claim-authorization-packet-current.json")
|
|
|
|
|
|
def run(command, **kwargs):
|
|
return subprocess.run(command, text=True, capture_output=True, check=False, **kwargs)
|
|
|
|
|
|
def service_state():
|
|
proc = run([
|
|
"systemctl",
|
|
"show",
|
|
"leoclean-gateway.service",
|
|
"-p",
|
|
"ActiveState",
|
|
"-p",
|
|
"SubState",
|
|
"-p",
|
|
"MainPID",
|
|
"-p",
|
|
"NRestarts",
|
|
"-p",
|
|
"ExecMainStartTimestamp",
|
|
"--no-pager",
|
|
])
|
|
state = {}
|
|
for line in proc.stdout.splitlines():
|
|
if "=" in line:
|
|
key, value = line.split("=", 1)
|
|
state[key] = value
|
|
return {"returncode": proc.returncode, "stderr": proc.stderr, "state": state}
|
|
|
|
|
|
def db_counts():
|
|
sql = """
|
|
select jsonb_build_object(
|
|
'public.claims', (select count(*) from public.claims),
|
|
'public.sources', (select count(*) from public.sources),
|
|
'public.claim_evidence', (select count(*) from public.claim_evidence),
|
|
'public.claim_edges', (select count(*) from public.claim_edges),
|
|
'kb_stage.kb_proposals', (select count(*) from kb_stage.kb_proposals)
|
|
)::text;
|
|
"""
|
|
proc = run(
|
|
["docker", "exec", "-i", "teleo-pg", "psql", "-U", "postgres", "-d", "teleo", "-At", "-q"],
|
|
input=sql,
|
|
)
|
|
parsed = None
|
|
if proc.returncode == 0 and proc.stdout.strip():
|
|
parsed = json.loads(proc.stdout.strip())
|
|
return {"returncode": proc.returncode, "stderr": proc.stderr, "counts": parsed}
|
|
|
|
|
|
def git_value(args):
|
|
proc = run(["git", "-C", str(repo), *args])
|
|
return {"returncode": proc.returncode, "stdout": proc.stdout.strip(), "stderr": proc.stderr.strip()}
|
|
|
|
|
|
payload = {
|
|
"deploy_head": git_value(["rev-parse", "HEAD"]),
|
|
"last_deploy_sha": {
|
|
"returncode": 0,
|
|
"stdout": Path("/opt/teleo-eval/.last-deploy-sha").read_text(encoding="utf-8").strip(),
|
|
"stderr": "",
|
|
},
|
|
"packet_present": packet_path.exists(),
|
|
"packet_bytes": packet_path.stat().st_size if packet_path.exists() else 0,
|
|
"service": service_state(),
|
|
"db_counts": db_counts(),
|
|
}
|
|
print(json.dumps(payload, sort_keys=True))
|
|
PY
|
|
printf '\n'
|