diff --git a/src/jlmkr/actions/stop.py b/src/jlmkr/actions/stop.py new file mode 100644 index 0000000..9babdb4 --- /dev/null +++ b/src/jlmkr/actions/stop.py @@ -0,0 +1,31 @@ +# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers +# +# SPDX-License-Identifier: LGPL-3.0-only + +import subprocess +import time + +from utils.console import eprint +from utils.jail_dataset import jail_is_running + + +def stop_jail(jail_name): + """ + Stop jail with given name and wait until stopped. + """ + + if not jail_is_running(jail_name): + return 0 + + returncode = subprocess.run(["machinectl", "poweroff", jail_name]).returncode + if returncode != 0: + eprint("Error while stopping jail.") + return returncode + + print(f"Wait for {jail_name} to stop", end="", flush=True) + + while jail_is_running(jail_name): + time.sleep(1) + print(".", end="", flush=True) + + return 0 diff --git a/src/jlmkr/donor/jlmkr.py b/src/jlmkr/donor/jlmkr.py index bb1526e..e2a5634 100755 --- a/src/jlmkr/donor/jlmkr.py +++ b/src/jlmkr/donor/jlmkr.py @@ -751,26 +751,7 @@ def edit_jail(jail_name): return 0 -def stop_jail(jail_name): - """ - Stop jail with given name and wait until stopped. - """ - - if not jail_is_running(jail_name): - return 0 - - returncode = subprocess.run(["machinectl", "poweroff", jail_name]).returncode - if returncode != 0: - eprint("Error while stopping jail.") - return returncode - - print(f"Wait for {jail_name} to stop", end="", flush=True) - - while jail_is_running(jail_name): - time.sleep(1) - print(".", end="", flush=True) - - return 0 +from actions.stop import stop_jail def remove_jail(jail_name):