47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Start all recreated Neko containers on dylive VPS (operator allowed recreate)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
|
|
try:
|
|
cmd = r"""
|
|
set -e
|
|
echo '=== before ==='
|
|
docker ps -a --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}'
|
|
cd /opt/douyinWEB/backend
|
|
.venv/bin/python - <<'PY'
|
|
from app import youtube_neko
|
|
desired = max(1, youtube_neko._desired_from_db())
|
|
print('desired', desired)
|
|
for i in range(1, desired + 1):
|
|
name = youtube_neko._container_name(i)
|
|
code, out = youtube_neko._run(['docker', 'start', name], timeout=90)
|
|
print(i, name, 'code', code, (out or '')[-120:])
|
|
youtube_neko._open_firewall(desired)
|
|
youtube_neko.sync_nginx_proxy(desired)
|
|
print('firewall+nginx synced')
|
|
PY
|
|
echo '=== after ==='
|
|
docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}'
|
|
curl -sS -m 10 -o /dev/null -w 'dylive=%{http_code}\n' https://dylive.nomadro.com/api/health
|
|
"""
|
|
_i, o, e = c.exec_command(cmd, timeout=600)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
return o.channel.recv_exit_status()
|
|
finally:
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|