mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-25 08:43:36 +05:00
refactor: tweak client setup and removal
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -144,7 +144,7 @@ def install_client(client: BaseWebClient) -> None:
|
||||
)
|
||||
|
||||
if kl_instances:
|
||||
symlink_webui_nginx_log(kl_instances)
|
||||
symlink_webui_nginx_log(client, kl_instances)
|
||||
cmd_sysctl_service("nginx", "restart")
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import List, get_args
|
||||
|
||||
from components.klipper.klipper import Klipper
|
||||
@@ -95,17 +94,19 @@ def enable_mainsail_remotemode() -> None:
|
||||
Logger.print_ok("Mainsails remote mode enabled!")
|
||||
|
||||
|
||||
def symlink_webui_nginx_log(klipper_instances: List[Klipper]) -> None:
|
||||
def symlink_webui_nginx_log(
|
||||
client: BaseWebClient, klipper_instances: List[Klipper]
|
||||
) -> None:
|
||||
Logger.print_status("Link NGINX logs into log directory ...")
|
||||
access_log = Path("/var/log/nginx/mainsail-access.log")
|
||||
error_log = Path("/var/log/nginx/mainsail-error.log")
|
||||
access_log = client.nginx_access_log
|
||||
error_log = client.nginx_error_log
|
||||
|
||||
for instance in klipper_instances:
|
||||
desti_access = instance.log_dir.joinpath("mainsail-access.log")
|
||||
desti_access = instance.log_dir.joinpath(access_log.name)
|
||||
if not desti_access.exists():
|
||||
desti_access.symlink_to(access_log)
|
||||
|
||||
desti_error = instance.log_dir.joinpath("mainsail-error.log")
|
||||
desti_error = instance.log_dir.joinpath(error_log.name)
|
||||
if not desti_error.exists():
|
||||
desti_error.symlink_to(error_log)
|
||||
|
||||
@@ -146,9 +147,7 @@ def backup_client_data(client: BaseWebClient) -> None:
|
||||
|
||||
bm = BackupManager()
|
||||
bm.backup_directory(f"{name}-{version}", src, dest)
|
||||
if name == "mainsail":
|
||||
c_json = MainsailData().client_dir.joinpath("config.json")
|
||||
bm.backup_file(c_json, dest)
|
||||
bm.backup_file(client.config_file, dest)
|
||||
bm.backup_file(NGINX_SITES_AVAILABLE.joinpath(name), dest)
|
||||
|
||||
|
||||
|
||||
@@ -80,23 +80,23 @@ def remove_file(file_path: Path, sudo=False) -> None:
|
||||
|
||||
def run_remove_routines(file: Path) -> None:
|
||||
try:
|
||||
if not file.exists():
|
||||
if not file.is_symlink() and not file.exists():
|
||||
Logger.print_info(f"File '{file}' does not exist. Skipped ...")
|
||||
return
|
||||
|
||||
if file.is_dir():
|
||||
shutil.rmtree(file)
|
||||
elif file.is_file():
|
||||
elif file.is_file() or file.is_symlink():
|
||||
file.unlink()
|
||||
else:
|
||||
raise OSError(f"File '{file}' is neither a file nor a directory!")
|
||||
Logger.print_ok("Successfully removed!")
|
||||
Logger.print_ok(f"File '{file}' was successfully removed!")
|
||||
except OSError as e:
|
||||
Logger.print_error(f"Unable to delete '{file}':\n{e}")
|
||||
try:
|
||||
Logger.print_info("Trying to remove with sudo ...")
|
||||
remove_with_sudo(file)
|
||||
Logger.print_ok("Successfully removed!")
|
||||
Logger.print_ok(f"File '{file}' was successfully removed!")
|
||||
except CalledProcessError as e:
|
||||
Logger.print_error(f"Error deleting '{file}' with sudo:\n{e}")
|
||||
Logger.print_error("Remove this directory manually!")
|
||||
|
||||
Reference in New Issue
Block a user