# -*- coding: utf-8 -*- """Push fixed restart_interface detection for wg-quick@ template units.""" from __future__ import annotations import sys from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") PASS = "4669805" ROOT = Path(__file__).resolve().parents[1] def main() -> int: g = paramiko.SSHClient() g.set_missing_host_key_policy(paramiko.AutoAddPolicy()) g.connect( "107.173.30.245", 4014, "eric", PASS, timeout=45, banner_timeout=120, allow_agent=False, look_for_keys=False, ) sftp = g.open_sftp() with sftp.file("/tmp/_wg_watch_v2.sh", "wb") as f: f.write((ROOT / "scripts/linux/wireguard_watch.sh").read_bytes()) sftp.close() _, o, e = g.exec_command( f"echo '{PASS}' | sudo -S -p '' bash -lc '" "install -m 755 /tmp/_wg_watch_v2.sh /opt/douyinWEB/scripts/linux/wireguard_watch.sh; " "sed -i \"s/\\r$//\" /opt/douyinWEB/scripts/linux/wireguard_watch.sh; " "systemctl restart douyinweb-wireguard-watch; " "sleep 1; systemctl is-active douyinweb-wireguard-watch; " "journalctl -u douyinweb-wireguard-watch -n 3 --no-pager; " "echo PUSH_OK'", timeout=40, ) print((o.read() + e.read()).decode("utf-8", "replace")) g.close() return 0 if __name__ == "__main__": raise SystemExit(main())