mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
action_utils: Add utility to ensure that service is stopped
- This could be used when the daemon can't be running while configuration is being updated. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
parent
0ea0a8b33c
commit
f501bc99ab
@ -64,6 +64,20 @@ def service_ensure_running(service_name):
|
||||
service_disable(service_name)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def service_ensure_stopped(service_name):
|
||||
"""Ensure a service is stopped and return to previous state."""
|
||||
starting_state = service_is_running(service_name)
|
||||
if starting_state:
|
||||
service_disable(service_name)
|
||||
|
||||
try:
|
||||
yield starting_state
|
||||
finally:
|
||||
if starting_state:
|
||||
service_enable(service_name)
|
||||
|
||||
|
||||
def service_is_enabled(service_name, strict_check=False):
|
||||
"""Check if service is enabled in systemd.
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user