Extract exec action

This commit is contained in:
jonct 2024-07-15 02:04:26 -04:00
parent d26e8cc518
commit dbb3dd4e22
No known key found for this signature in database
2 changed files with 25 additions and 18 deletions

24
src/jlmkr/actions/exec.py Normal file
View File

@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: © 2024 Jip-Hop and the Jailmakers <https://github.com/Jip-Hop/jailmaker>
#
# SPDX-License-Identifier: LGPL-3.0-only
import subprocess
def exec_jail(jail_name, cmd):
"""
Execute a command in the jail with given name.
"""
return subprocess.run(
[
"systemd-run",
"--machine",
jail_name,
"--quiet",
"--pipe",
"--wait",
"--collect",
"--service-type=exec",
*cmd,
]
).returncode

View File

@ -141,24 +141,7 @@ from utils.chroot import Chroot
from utils.console import eprint, fail
from utils.jail_dataset import get_jail_path, get_jail_config_path, get_jail_rootfs_path
def exec_jail(jail_name, cmd):
"""
Execute a command in the jail with given name.
"""
return subprocess.run(
[
"systemd-run",
"--machine",
jail_name,
"--quiet",
"--pipe",
"--wait",
"--collect",
"--service-type=exec",
*cmd,
]
).returncode
from actions.exec import exec_jail
def status_jail(jail_name, args):