mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
action_utils: Implement method for starting a service temporarily
Used when a service is needed for an operation but we don't wish to keep it running after the operation. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
22671510e6
commit
a488ee4d43
@ -48,6 +48,20 @@ def service_is_running(servicename):
|
||||
return False
|
||||
|
||||
|
||||
@contextmanager
|
||||
def service_ensure_running(service_name):
|
||||
"""Ensure a service is running and return to previous state."""
|
||||
starting_state = service_is_running(service_name)
|
||||
if not starting_state:
|
||||
service_enable(service_name)
|
||||
|
||||
try:
|
||||
yield starting_state
|
||||
finally:
|
||||
if not starting_state:
|
||||
service_disable(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