55 lines
2.1 KiB
Python
55 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Unstick a manager deploy where the container name collides with a
|
|
half-removed sibling. Removes everything named heicode* (except the
|
|
openbao auxiliary), then `compose up -d` to recreate cleanly.
|
|
"""
|
|
|
|
import os, sys, paramiko, time
|
|
|
|
HOST = os.environ.get("MGR_HOST", "20.24.50.121")
|
|
USER = os.environ.get("MGR_USER", "heicode")
|
|
PASS = os.environ.get("MGR_PASS", "")
|
|
|
|
if not PASS:
|
|
print("MGR_PASS not set", file=sys.stderr); sys.exit(2)
|
|
|
|
def run(client, cmd, timeout=900):
|
|
print(f"\n$ {cmd}", flush=True)
|
|
_, stdout, _ = client.exec_command(cmd, timeout=timeout, get_pty=True)
|
|
for raw in iter(stdout.readline, ""):
|
|
if not raw: break
|
|
sys.stdout.write(raw.encode("ascii","replace").decode("ascii"))
|
|
sys.stdout.flush()
|
|
return stdout.channel.recv_exit_status()
|
|
|
|
client = paramiko.SSHClient()
|
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
client.connect(hostname=HOST, port=22, username=USER, password=PASS,
|
|
look_for_keys=False, allow_agent=False, timeout=30)
|
|
|
|
# Find repo
|
|
run(client, "ls -d ~/heicode-mananger ~/heicode 2>/dev/null")
|
|
|
|
# Show all containers (running + stopped) related to heicode
|
|
run(client, "sudo docker ps -a --filter name=heicode --format 'table {{.Names}}\\t{{.Status}}\\t{{.Image}}'")
|
|
|
|
# Remove any container that is exactly 'heicode' (the conflicting old one)
|
|
# AND any *_heicode temp.
|
|
run(client, "sudo docker rm -f heicode 2>/dev/null || true")
|
|
run(client, "sudo docker ps -aq --filter name=_heicode | xargs -r sudo docker rm -f")
|
|
|
|
run(client, "sudo docker ps -a --filter name=heicode --format 'table {{.Names}}\\t{{.Status}}'")
|
|
|
|
# Re-up
|
|
repo = "/home/heicode/heicode-mananger"
|
|
# Try both common paths
|
|
run(client, f"test -d {repo} || ls -d ~/heicode-mananger 2>/dev/null")
|
|
run(client, f"cd ~/heicode-mananger/heicode && sudo docker compose -f docker-compose.azure-vm.yml up -d heicode 2>&1", timeout=600)
|
|
|
|
time.sleep(8)
|
|
run(client, "sudo docker ps --filter name=heicode --format 'table {{.Names}}\\t{{.Status}}\\t{{.CreatedAt}}'")
|
|
run(client, "sudo docker logs --tail=20 heicode")
|
|
|
|
client.close()
|
|
print("\nUNSTICK DONE")
|