From edd1903423b9f81ee83da23829634335abc23f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jake=20Buchholz=20G=C3=B6kt=C3=BCrk?= Date: Sun, 5 Jun 2022 12:22:17 -0700 Subject: [PATCH] Add Support for Systems Using OpenRC Obsoletes #98 Resolves #50 --- src/mount_efs/__init__.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/mount_efs/__init__.py b/src/mount_efs/__init__.py index c6a88507..a85a7bf4 100755 --- a/src/mount_efs/__init__.py +++ b/src/mount_efs/__init__.py @@ -1294,6 +1294,11 @@ def get_init_system(comm_file="/proc/1/comm"): init_system = f.read().strip() except IOError: logging.warning("Unable to read %s", comm_file) + + # OpenRC init system manages services a little differently + if init_system == "init" and os.path.isfile("/sbin/openrc"): + init_system = "openrc-init" + logging.debug("Detected OpenRC init system") else: init_system = "launchd" @@ -1353,6 +1358,24 @@ def start_watchdog(init_system): elif "start" in str(status): logging.debug("%s is already running", WATCHDOG_SERVICE) + elif init_system == "openrc-init": + proc = subprocess.Popen( + ["/sbin/service", WATCHDOG_SERVICE, "status"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True, + ) + status, _ = proc.communicate() + if "stopped" in str(status): + subprocess.Popen( + ["/sbin/service", WATCHDOG_SERVICE, "start"], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + close_fds=True, + ) + elif "started" in str(status): + logging.debug("%s is already running", WATCHDOG_SERVICE) + elif init_system == "systemd": rc = subprocess.call( ["systemctl", "is-active", "--quiet", WATCHDOG_SERVICE], close_fds=True