From 1bd58c951ef796e819290bbf9037e7e4d09b88db Mon Sep 17 00:00:00 2001 From: Jip-Hop <2871973+Jip-Hop@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:09:16 +0200 Subject: [PATCH] Cleanup log and status code --- jlmkr.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/jlmkr.py b/jlmkr.py index ee61b7c..f00c77f 100755 --- a/jlmkr.py +++ b/jlmkr.py @@ -490,23 +490,23 @@ def exec_jail(jail_name, cmd): ).returncode -def status_jail(jail_name, cmd_args): +def status_jail(jail_name, 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}", *cmd_args, ] + ["systemctl", "status", f"{SHORTNAME}-{jail_name}", *args] ).returncode -def log_jail(jail_name, cmd_args): +def log_jail(jail_name, args): """ Show the log file of the jail with given name. """ - if not cmd_args: cmd_args = ["-xe"] - return subprocess.run(["journalctl", *cmd_args, "-u", f"{SHORTNAME}-{jail_name}"]).returncode + return subprocess.run( + ["journalctl", "-u", f"{SHORTNAME}-{jail_name}", *args] + ).returncode def shell_jail(args): @@ -1885,13 +1885,6 @@ 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="*", @@ -1904,6 +1897,18 @@ def main(): help="args to pass to machinectl shell", ) + commands["log"].add_argument( + "args", + nargs="*", + help="args to pass to journalctl", + ) + + commands["status"].add_argument( + "args", + nargs="*", + help="args to pass to systemctl", + ) + commands["create"].add_argument( "jail_name", # nargs="?",