diff --git a/plinth/modules/calibre/privileged.py b/plinth/modules/calibre/privileged.py index 962f2f575..86d320aa1 100644 --- a/plinth/modules/calibre/privileged.py +++ b/plinth/modules/calibre/privileged.py @@ -28,9 +28,9 @@ def create_library(name: str): calibre.validate_library_name(name) library = LIBRARIES_PATH / name library.mkdir(mode=0o755) # Raise exception if already exists - subprocess.call( + action_utils.run( ['calibredb', '--with-library', library, 'list_categories'], - stdout=subprocess.DEVNULL) + stdout=subprocess.DEVNULL, check=False) # Force systemd StateDirectory= logic to assign proper ownership to the # DynamicUser= diff --git a/plinth/modules/calibre/tests/test_privileged.py b/plinth/modules/calibre/tests/test_privileged.py index 6b41173f8..346897e25 100644 --- a/plinth/modules/calibre/tests/test_privileged.py +++ b/plinth/modules/calibre/tests/test_privileged.py @@ -29,9 +29,8 @@ def fixture_patch(): path = pathlib.Path(args[0][2]) / 'metadata.db' path.touch() - with patch('subprocess.call') as subprocess_call, \ - patch('subprocess.run'), patch('shutil.chown'): - subprocess_call.side_effect = side_effect + with patch('subprocess.run') as subprocess_run, patch('shutil.chown'): + subprocess_run.side_effect = side_effect yield diff --git a/plinth/modules/ejabberd/privileged.py b/plinth/modules/ejabberd/privileged.py index a682a073e..49d7a68a8 100644 --- a/plinth/modules/ejabberd/privileged.py +++ b/plinth/modules/ejabberd/privileged.py @@ -145,7 +145,7 @@ def pre_change_hostname(old_hostname: str, new_hostname: str): logger.info('ejabberdctl not found') return - subprocess.call(['ejabberdctl', 'backup', EJABBERD_BACKUP]) + action_utils.run(['ejabberdctl', 'backup', EJABBERD_BACKUP], check=False) subprocess.check_output([ 'ejabberdctl', 'mnesia-change-nodename', 'ejabberd@' + old_hostname, 'ejabberd@' + new_hostname, EJABBERD_BACKUP, EJABBERD_BACKUP_NEW @@ -160,12 +160,12 @@ def change_hostname(): return action_utils.service_stop('ejabberd') - subprocess.call(['pkill', '-u', 'ejabberd']) + action_utils.run(['pkill', '-u', 'ejabberd'], check=False) # Make sure there aren't files in the Mnesia spool dir os.makedirs('/var/lib/ejabberd/oldfiles', exist_ok=True) - subprocess.call('mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/', - shell=True) + action_utils.run('mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/', + shell=True, check=False) action_utils.service_start('ejabberd') @@ -278,7 +278,7 @@ def mam(command: str) -> bool | None: yaml.dump(conf, file_handle) if action_utils.service_is_running('ejabberd'): - subprocess.call(['ejabberdctl', 'reload_config']) + action_utils.run(['ejabberdctl', 'reload_config'], check=False) return None @@ -359,7 +359,7 @@ def configure_turn(turn_server_config: dict[str, Any], managed: bool): Path(EJABBERD_MANAGED_COTURN).unlink(missing_ok=True) if action_utils.service_is_running('ejabberd'): - subprocess.call(['ejabberdctl', 'reload_config']) + action_utils.run(['ejabberdctl', 'reload_config'], check=False) def _get_version(): diff --git a/plinth/modules/openvpn/privileged.py b/plinth/modules/openvpn/privileged.py index 50f64c722..5679a5660 100644 --- a/plinth/modules/openvpn/privileged.py +++ b/plinth/modules/openvpn/privileged.py @@ -104,8 +104,8 @@ def _setup_firewall(): 'firewall-cmd', '--zone', 'internal', '--{}-interface'.format(operation), interface ] - subprocess.call(command) - subprocess.call(command + ['--permanent']) + action_utils.run(command, check=False) + action_utils.run(command + ['--permanent'], check=False) def _is_tunplus_enabled(): """Return whether tun+ interface is already added.""" diff --git a/plinth/modules/power/privileged.py b/plinth/modules/power/privileged.py index 06e22967c..4f468d9c9 100644 --- a/plinth/modules/power/privileged.py +++ b/plinth/modules/power/privileged.py @@ -1,18 +1,17 @@ # SPDX-License-Identifier: AGPL-3.0-or-later """Shutdown/restart the system.""" -import subprocess - +from plinth import action_utils from plinth.actions import privileged @privileged def restart(): """Restart the system.""" - subprocess.call('reboot') + action_utils.run('reboot', check=False) @privileged def shutdown(): """Shut down the system.""" - subprocess.call(['shutdown', 'now']) + action_utils.run(['shutdown', 'now'], check=False)