From d26e8cc5180f80a0c66e1ba715274f037707d37a Mon Sep 17 00:00:00 2001 From: jonct <2807816+jonct@users.noreply.github.com> Date: Mon, 15 Jul 2024 02:01:35 -0400 Subject: [PATCH] Extract restart action --- src/jlmkr/actions/restart.py | 24 ++++++++++++++++++++++++ src/jlmkr/donor/jlmkr.py | 16 ++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 src/jlmkr/actions/restart.py diff --git a/src/jlmkr/actions/restart.py b/src/jlmkr/actions/restart.py new file mode 100644 index 0000000..1740230 --- /dev/null +++ b/src/jlmkr/actions/restart.py @@ -0,0 +1,24 @@ +# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers +# +# SPDX-License-Identifier: LGPL-3.0-only + + +import subprocess +import time + +from actions.start import start_jail +from actions.stop import stop_jail +from utils.console import eprint + + +def restart_jail(jail_name): + """ + Restart jail with given name. + """ + + returncode = stop_jail(jail_name) + if returncode != 0: + eprint("Abort restart.") + return returncode + + return start_jail(jail_name) diff --git a/src/jlmkr/donor/jlmkr.py b/src/jlmkr/donor/jlmkr.py index e2a5634..b70d4be 100755 --- a/src/jlmkr/donor/jlmkr.py +++ b/src/jlmkr/donor/jlmkr.py @@ -187,20 +187,8 @@ def shell_jail(args): return subprocess.run(["machinectl", "shell"] + args).returncode -from actions.start import add_hook, start_jail - - -def restart_jail(jail_name): - """ - Restart jail with given name. - """ - - returncode = stop_jail(jail_name) - if returncode != 0: - eprint("Abort restart.") - return returncode - - return start_jail(jail_name) +from actions.start import start_jail +from actions.restart import restart_jail def cleanup(jail_path):