mirror of
https://github.com/anten-ka/gotelegram_pro.git
synced 2026-05-19 13:26:02 +00:00
v2.5.0: harden telemt user reloads
This commit is contained in:
@@ -54,6 +54,8 @@ LANG_RE = re.compile(r"^(en|ru)$")
|
||||
SENSITIVE_CONFIG_KEYS = {"secret"}
|
||||
BACKUP_NAME_RE = re.compile(r"^[A-Za-z0-9_.-]+\.tar\.gz(\.enc)?$")
|
||||
MAX_UNIQUE_IP_LIMIT = 1000000
|
||||
TELEMT_RESTART_DEBOUNCE_SECONDS = float(os.getenv("GOTELEGRAM_TELEMT_RESTART_DEBOUNCE", "8"))
|
||||
_LAST_TELEMT_RESTART = 0.0
|
||||
TRAFFIC_WINDOWS = {
|
||||
"15m": 15 * 60,
|
||||
"1h": 60 * 60,
|
||||
@@ -405,6 +407,15 @@ def restart_service(name: str) -> bool:
|
||||
|
||||
|
||||
def request_service_restart(name: str) -> bool:
|
||||
global _LAST_TELEMT_RESTART
|
||||
if name == "telemt":
|
||||
now = time.monotonic()
|
||||
if _LAST_TELEMT_RESTART > 0 and now - _LAST_TELEMT_RESTART < TELEMT_RESTART_DEBOUNCE_SECONDS:
|
||||
status = service_status(name)
|
||||
if status in {"running", "activating"}:
|
||||
return True
|
||||
run(["systemctl", "reset-failed", name], timeout=5)
|
||||
_LAST_TELEMT_RESTART = now
|
||||
code, _, _ = run(["systemctl", "--no-block", "restart", name], timeout=5)
|
||||
return code == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user