Cleanup log and status code

This commit is contained in:
Jip-Hop 2024-06-28 12:09:16 +02:00
parent 1b796ca2cf
commit 1bd58c951e
1 changed files with 18 additions and 13 deletions

View File

@ -490,23 +490,23 @@ def exec_jail(jail_name, cmd):
).returncode ).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. Show the status of the systemd service wrapping the jail with given name.
""" """
# Alternatively `machinectl status jail_name` could be used # Alternatively `machinectl status jail_name` could be used
if not cmd_args: cmd_args = []
return subprocess.run( return subprocess.run(
["systemctl", "status", f"{SHORTNAME}-{jail_name}", *cmd_args, ] ["systemctl", "status", f"{SHORTNAME}-{jail_name}", *args]
).returncode ).returncode
def log_jail(jail_name, cmd_args): def log_jail(jail_name, args):
""" """
Show the log file of the jail with given name. Show the log file of the jail with given name.
""" """
if not cmd_args: cmd_args = ["-xe"] return subprocess.run(
return subprocess.run(["journalctl", *cmd_args, "-u", f"{SHORTNAME}-{jail_name}"]).returncode ["journalctl", "-u", f"{SHORTNAME}-{jail_name}", *args]
).returncode
def shell_jail(args): def shell_jail(args):
@ -1885,13 +1885,6 @@ def main():
for cmd in ["edit", "exec", "log", "remove", "restart", "start", "status", "stop"]: for cmd in ["edit", "exec", "log", "remove", "restart", "start", "status", "stop"]:
commands[cmd].add_argument("jail_name", help="name of the jail") 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( commands["exec"].add_argument(
"cmd", "cmd",
nargs="*", nargs="*",
@ -1904,6 +1897,18 @@ def main():
help="args to pass to machinectl shell", 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( commands["create"].add_argument(
"jail_name", # "jail_name", #
nargs="?", nargs="?",