Skip to content

Commit

Permalink
Extract stop action
Browse files Browse the repository at this point in the history
  • Loading branch information
jonct committed Jul 15, 2024
1 parent c523974 commit ef479d7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
31 changes: 31 additions & 0 deletions src/jlmkr/actions/stop.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 1 addition & 20 deletions src/jlmkr/donor/jlmkr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit ef479d7

Please sign in to comment.