From d21f279f898fb630a528582e8f026f7e3f38b59b Mon Sep 17 00:00:00 2001 From: kzolotarev95 Date: Mon, 29 Jun 2026 06:10:21 +0400 Subject: [PATCH] Add VPS Xray reload action --- README.md | 10 ++++++++ vps/owrt-remote-hub.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/README.md b/README.md index 0af12dc..e979aa0 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,16 @@ sudo /opt/owrt-remote/owrt-remote-hub.py render-xray --out /etc/xray/owrt-remote sudo systemctl restart owrt-remote-xray ``` +Если кнопка `Админка` пишет `proxy error: [Errno 111] Connection refused`, значит VPS Xray еще не слушает `entry_port` этого роутера. В Hub нажми `Обновить Xray VPS` или выполни: + +```sh +sudo /opt/owrt-remote/owrt-remote-hub.py render-xray --out /etc/xray/owrt-remote.json +sudo systemctl restart owrt-remote-xray +sudo ss -lntp | grep -E ':(8443|18080|18090|18100|18095)\b' +``` + +Для роутера с `entry 18095` в выводе должен появиться `127.0.0.1:18095`. + Сгенерировать Xray config для VPS: ```sh diff --git a/vps/owrt-remote-hub.py b/vps/owrt-remote-hub.py index 44de506..a88ebb1 100644 --- a/vps/owrt-remote-hub.py +++ b/vps/owrt-remote-hub.py @@ -8,6 +8,7 @@ import json import os import secrets import sqlite3 +import subprocess import sys import time import urllib.parse @@ -481,6 +482,33 @@ def make_router_xray_config(row): } +def reload_vps_xray(db_path=DB_PATH): + out = Path(os.environ.get("OWRT_REMOTE_XRAY_CONFIG", "/etc/xray/owrt-remote.json")) + service = os.environ.get("OWRT_REMOTE_XRAY_SERVICE", "owrt-remote-xray") + with connect(db_path) as conn: + init_db(conn) + rows = list_router_rows(conn) + config = make_server_xray_config(rows) + out.parent.mkdir(parents=True, exist_ok=True) + out.write_text(json.dumps(config, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") + try: + os.chmod(out, 0o600) + except OSError: + pass + result = subprocess.run( + ["systemctl", "restart", service], + text=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + timeout=20, + check=False, + ) + if result.returncode != 0: + detail = (result.stderr or result.stdout or "").strip() + raise RuntimeError(f"systemctl restart {service} failed: {detail}") + return {"config": str(out), "service": service, "routers": len(rows)} + + def make_openwrt_config(row, hub_url): lines = [ "uci -q delete owrtremote.main", @@ -581,6 +609,7 @@ input,select{{min-width:0;border:1px solid var(--line);border-radius:8px;padding
Hub online
+ Выйти