From 1b796ca2cf58ca54a5546516bba462a642ce61d8 Mon Sep 17 00:00:00 2001 From: Lockszmith Date: Thu, 27 Jun 2024 18:18:09 -0400 Subject: [PATCH] Added passing arguments to log and status This allows automated tests to run smoother. Currently there are 2 tests that block the console for input: * edit * shell --- jlmkr.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/jlmkr.py b/jlmkr.py index ac9d2d0..ee61b7c 100755 --- a/jlmkr.py +++ b/jlmkr.py @@ -490,21 +490,23 @@ def exec_jail(jail_name, cmd): ).returncode -def status_jail(jail_name): +def status_jail(jail_name, cmd_args): """ Show the status of the systemd service wrapping the jail with given name. """ # Alternatively `machinectl status jail_name` could be used + if not cmd_args: cmd_args = [] return subprocess.run( - ["systemctl", "status", f"{SHORTNAME}-{jail_name}"] + ["systemctl", "status", f"{SHORTNAME}-{jail_name}", *cmd_args, ] ).returncode -def log_jail(jail_name): +def log_jail(jail_name, cmd_args): """ Show the log file of the jail with given name. """ - return subprocess.run(["journalctl", "-u", f"{SHORTNAME}-{jail_name}"]).returncode + if not cmd_args: cmd_args = ["-xe"] + return subprocess.run(["journalctl", *cmd_args, "-u", f"{SHORTNAME}-{jail_name}"]).returncode def shell_jail(args): @@ -1807,7 +1809,7 @@ def main(): title="commands", dest="command", metavar="", parser_class=CustomSubParser ) - split_commands = ["create", "exec"] + split_commands = ["create", "exec", "log", "status"] commands = {} for d in [ @@ -1883,6 +1885,13 @@ def main(): for cmd in ["edit", "exec", "log", "remove", "restart", "start", "status", "stop"]: commands[cmd].add_argument("jail_name", help="name of the jail") + for cmd in ["log", "status"]: + commands[cmd].add_argument( + "cmd_args", + nargs="*", + help="journalctl arguments", + ) + commands["exec"].add_argument( "cmd", nargs="*",