action_utils: Drop support for non-systemd environments

- There hasn't been a need for this for a long time. non-systemd environments
haven't been worked on or tested for in a long time.

- Keep the is_systemd_running() method for future use.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2022-10-07 01:18:37 -07:00 committed by James Valleroy
parent e3a67da8ec
commit 6a0493a752
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
4 changed files with 10 additions and 17 deletions

View File

@ -39,13 +39,8 @@ def service_is_running(servicename):
Does not need to run as root.
"""
try:
if is_systemd_running():
subprocess.run(['systemctl', 'status', servicename], check=True,
stdout=subprocess.DEVNULL)
else:
subprocess.run(['service', servicename, 'status'], check=True,
stdout=subprocess.DEVNULL)
subprocess.run(['systemctl', 'status', servicename], check=True,
stdout=subprocess.DEVNULL)
return True
except subprocess.CalledProcessError:
# If a service is not running we get a status code != 0 and
@ -126,12 +121,8 @@ def service_reload(service_name):
def service_action(service_name, action):
"""Perform the given action on the service_name."""
if is_systemd_running():
subprocess.run(['systemctl', action, service_name],
stdout=subprocess.DEVNULL, check=False)
else:
subprocess.run(['service', service_name, action],
stdout=subprocess.DEVNULL, check=False)
subprocess.run(['systemctl', action, service_name],
stdout=subprocess.DEVNULL, check=False)
def webserver_is_enabled(name, kind='config'):

View File

@ -30,7 +30,7 @@ def fixture_patch():
path.touch()
with patch('subprocess.call') as subprocess_call, \
patch('shutil.chown'):
patch('subprocess.run'), patch('shutil.chown'):
subprocess_call.side_effect = side_effect
yield

View File

@ -66,7 +66,7 @@ def fixture_test_configuration(conf_file):
def _set_turn_configuration(config=managed_configuration, managed=True):
with patch('plinth.privileged.service.is_running', return_value=False):
with patch('plinth.action_utils.service_is_running', return_value=False):
ejabberd.update_turn_configuration(config, managed=managed)

View File

@ -72,12 +72,14 @@ updated_coturn_configuration = TurnConfiguration(
def _set_managed_configuration(config=coturn_configuration):
matrixsynapse.update_turn_configuration(config)
with patch('plinth.action_utils.service_try_restart'):
matrixsynapse.update_turn_configuration(config)
def _set_overridden_configuration(
config=overridden_configuration):
matrixsynapse.update_turn_configuration(config, managed=False)
with patch('plinth.action_utils.service_try_restart'):
matrixsynapse.update_turn_configuration(config, managed=False)
def _assert_conf(expected_configuration, expected_managed):