Extract stop action

This commit is contained in:
jonct 2024-07-15 01:57:55 -04:00
parent c5239749b9
commit ef479d7052
No known key found for this signature in database
2 changed files with 32 additions and 20 deletions

31
src/jlmkr/actions/stop.py Normal file
View File

@ -0,0 +1,31 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# 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

View File

@ -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):