dodatkowe poprawki i funkcje
This commit is contained in:
23
app.py
23
app.py
@@ -108,12 +108,10 @@ def maskToken(token: str | None) -> str:
|
||||
return token[:4] + "*" * (len(token) - 8) + token[-4:]
|
||||
|
||||
def commandCandidates(name: str):
|
||||
# 1) konfiguracja ma priorytet
|
||||
sect = f"service:{name}"
|
||||
if cfg.has_section(sect) and cfg.has_option(sect, "command"):
|
||||
return [cfg.get(sect, "command")]
|
||||
|
||||
# 2) auto-kandydaci zależnie od dostępności
|
||||
cmds = []
|
||||
if shutil.which("systemctl"):
|
||||
cmds += [f"systemctl reload {name}", f"systemctl restart {name}"]
|
||||
@@ -121,10 +119,17 @@ def commandCandidates(name: str):
|
||||
cmds += [f"service {name} reload", f"service {name} restart"]
|
||||
if shutil.which("rc-service"):
|
||||
cmds += [f"rc-service {name} reload", f"rc-service {name} restart"]
|
||||
# 3) ostatnia deska ratunku: HUP
|
||||
if shutil.which("pkill"):
|
||||
cmds += [f"pkill -HUP {name}"]
|
||||
return cmds or [f"pkill -HUP {name}"]
|
||||
|
||||
pid_file = cfg.get(sect, "pid_file", fallback=None)
|
||||
if pid_file and os.path.isfile(pid_file) and shutil.which("kill"):
|
||||
cmds += [f"kill -HUP $(cat {pid_file})"]
|
||||
if shutil.which("pgrep") and shutil.which("kill"):
|
||||
cmds += [f"kill -HUP $(pgrep -o {name})"]
|
||||
|
||||
return cmds or []
|
||||
|
||||
|
||||
def reloadService(name: str):
|
||||
for cmd in commandCandidates(name):
|
||||
@@ -208,10 +213,12 @@ def writeHostsAtomic(new_content: str, path: str = "/etc/hosts", backup_dir: str
|
||||
# kopia zapasowa
|
||||
if backup_dir:
|
||||
os.makedirs(backup_dir, exist_ok=True)
|
||||
ts = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
||||
backup_path = os.path.join(backup_dir, f"hosts.{ts}.bak")
|
||||
shutil.copy2(path, backup_path)
|
||||
info["backup"] = backup_path
|
||||
try:
|
||||
shutil.copy2(path, backup_path)
|
||||
info["backup"] = backup_path
|
||||
except Exception as e:
|
||||
logger.warning(f"Backup nieudany: {e}")
|
||||
|
||||
|
||||
# zapis atomowy
|
||||
dir_name = os.path.dirname(path) or "."
|
||||
|
Reference in New Issue
Block a user