diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-09-20 17:16:44 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-09-20 17:16:44 +0200 |
commit | b535300858d8bcd8f350da0949de0bd135e82f73 (patch) | |
tree | a517982ab80e794249767c291505b0aa02b94a11 | |
parent | a78183e1854ba1588fc6f3ee6ba83f4f3805865e (diff) | |
download | vyos-1x-b535300858d8bcd8f350da0949de0bd135e82f73.tar.gz vyos-1x-b535300858d8bcd8f350da0949de0bd135e82f73.zip |
vyos.util: add is_systemd_service_active() helper function
Required by the vyos.ifconfig library - backported from 1.4 (current)
-rw-r--r-- | python/vyos/util.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 45b1d7bf2..9f01d504d 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -704,8 +704,16 @@ def get_interface_config(interface): tmp = loads(cmd(f'ip -d -j link show {interface}'))[0] return tmp +def is_systemd_service_active(service): + """ Test is a specified systemd service is activated. + Returns True if service is active, false otherwise. + Copied from: https://unix.stackexchange.com/a/435317 """ + tmp = cmd(f'systemctl show --value -p ActiveState {service}') + return bool((tmp == 'active')) + 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)) + Returns True if service is running, false otherwise. + Copied from: https://unix.stackexchange.com/a/435317 """ + tmp = cmd(f'systemctl show --value -p SubState {service}') + return bool((tmp == 'running')) |