From f520182b56e34428e9d9491ba062025cc9bea971 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 30 Jul 2021 07:27:25 +0200 Subject: vyos.util: add is_systemd_service_running() helper function Test is a specified systemd service is actually running. Returns True if service is running, false otherwise. --- python/vyos/util.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/vyos/util.py b/python/vyos/util.py index d5cd46a6c..59f9f1c44 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -804,3 +804,9 @@ def make_incremental_progressbar(increment: float): # Ignore further calls. while True: yield + +def is_systemd_service_running(service): + """ Test is a specified systemd service is actually running. + Returns True if service is running, false otherwise. """ + tmp = run(f'systemctl is-active --quiet {service}') + return bool((tmp == 0)) -- cgit v1.2.3