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