diff --git a/daemon/core/services/defaults/frrservices/services.py b/daemon/core/services/defaults/frrservices/services.py index df1c1289..3305f169 100644 --- a/daemon/core/services/defaults/frrservices/services.py +++ b/daemon/core/services/defaults/frrservices/services.py @@ -8,6 +8,7 @@ from core.nodes.physical import Rj45Node from core.nodes.wireless import WirelessNode from core.services.base import CoreService +from core.nodes.base import CoreNode GROUP: str = "FRR" FRR_STATE_DIR: str = "/var/run/frr" @@ -92,6 +93,14 @@ class FRRZebra(CoreService): startup: list[str] = ["bash frrboot.sh zebra"] validate: list[str] = ["pidof zebra"] shutdown: list[str] = ["pkill -f zebra"] + path: str = "/usr/local/sbin /usr/sbin /usr/lib/frr /usr/libexec/frr" + + def __init__(self, node: CoreNode = None) -> None: + CoreService.__init__(self, node) + self.path = self.node.session.options.get( + "frr_sbin_search", + default=self.path, + ).strip('"') def data(self) -> dict[str, Any]: frr_conf = self.files[0] @@ -100,7 +109,7 @@ def data(self) -> dict[str, Any]: ).strip('"') frr_sbin_search = self.node.session.options.get( "frr_sbin_search", - default="/usr/local/sbin /usr/sbin /usr/lib/frr /usr/libexec/frr", + default=self.path, ).strip('"') services = [] diff --git a/daemon/core/services/manager.py b/daemon/core/services/manager.py index 06d619fa..7f2b4f80 100644 --- a/daemon/core/services/manager.py +++ b/daemon/core/services/manager.py @@ -68,7 +68,7 @@ def add(self, service: type[CoreService]) -> None: # validate dependent executables are present for executable in service.executables: try: - utils.which(executable, required=True) + utils.which(executable, required=True, path=hasattr(service, "path") and service.path or None) except CoreError as e: raise CoreError(f"service({service.name}): {e}") diff --git a/daemon/core/utils.py b/daemon/core/utils.py index 6eef2263..9e11ee44 100644 --- a/daemon/core/utils.py +++ b/daemon/core/utils.py @@ -146,7 +146,7 @@ def close_onexec(fd: int) -> None: fcntl.fcntl(fd, fcntl.F_SETFD, fdflags | fcntl.FD_CLOEXEC) -def which(command: str, required: bool) -> str | None: +def which(command: str, required: bool, path: str | None = None) -> str | None: """ Find location of desired executable within current PATH. @@ -155,7 +155,7 @@ def which(command: str, required: bool) -> str | None: :return: command location or None :raises ValueError: when not found and required """ - found_path = shutil.which(command) + found_path = shutil.which(command, path=path and path.replace(" ", ":")) if found_path is None and required: raise CoreError(f"failed to find required executable({command}) in path") return found_path