Add restart command
This commit is contained in:
parent
ed7a883f63
commit
1c83bb2dc7
48
jlmkr.py
48
jlmkr.py
|
@ -453,6 +453,18 @@ def start_jail(jail_name, check_startup_enabled=False):
|
||||||
return returncode
|
return returncode
|
||||||
|
|
||||||
|
|
||||||
|
def restart_jail(jail_name):
|
||||||
|
"""
|
||||||
|
Restart jail with given name.
|
||||||
|
"""
|
||||||
|
returncode = stop_jail_and_wait(jail_name)
|
||||||
|
if returncode != 0:
|
||||||
|
eprint("Abort restart.")
|
||||||
|
return returncode
|
||||||
|
|
||||||
|
return start_jail(jail_name)
|
||||||
|
|
||||||
|
|
||||||
def cleanup(jail_path):
|
def cleanup(jail_path):
|
||||||
"""
|
"""
|
||||||
Cleanup after aborted jail creation.
|
Cleanup after aborted jail creation.
|
||||||
|
@ -1090,6 +1102,25 @@ def edit_jail(jail_name):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def stop_jail_and_wait(jail_name):
|
||||||
|
"""
|
||||||
|
Wait for jail with given name to stop.
|
||||||
|
"""
|
||||||
|
|
||||||
|
returncode = stop_jail(jail_name)
|
||||||
|
if returncode != 0:
|
||||||
|
eprint("Error while stopping jail.")
|
||||||
|
return returncode
|
||||||
|
|
||||||
|
print(f"Wait for {jail_name} to stop", end="", flush=True)
|
||||||
|
# Need to sleep since deleting immediately after stop causes problems...
|
||||||
|
while jail_is_running(jail_name):
|
||||||
|
time.sleep(1)
|
||||||
|
print(".", end="", flush=True)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def remove_jail(jail_name):
|
def remove_jail(jail_name):
|
||||||
"""
|
"""
|
||||||
Remove jail with given name.
|
Remove jail with given name.
|
||||||
|
@ -1107,12 +1138,10 @@ def remove_jail(jail_name):
|
||||||
if check == jail_name:
|
if check == jail_name:
|
||||||
jail_path = get_jail_path(jail_name)
|
jail_path = get_jail_path(jail_name)
|
||||||
if jail_is_running(jail_name):
|
if jail_is_running(jail_name):
|
||||||
print(f"\nWait for {jail_name} to stop...", end="")
|
print()
|
||||||
stop_jail(jail_name)
|
returncode = stop_jail_and_wait(jail_name)
|
||||||
# Need to sleep since deleting immediately after stop causes problems...
|
if returncode != 0:
|
||||||
while jail_is_running(jail_name):
|
return returncode
|
||||||
time.sleep(1)
|
|
||||||
print(".", end="", flush=True)
|
|
||||||
|
|
||||||
print(f"\nCleaning up: {jail_path}")
|
print(f"\nCleaning up: {jail_path}")
|
||||||
shutil.rmtree(jail_path)
|
shutil.rmtree(jail_path)
|
||||||
|
@ -1313,6 +1342,10 @@ def main():
|
||||||
name="start", epilog=DISCLAIMER, help="start a previously created jail"
|
name="start", epilog=DISCLAIMER, help="start a previously created jail"
|
||||||
).add_argument("name", help="name of the jail")
|
).add_argument("name", help="name of the jail")
|
||||||
|
|
||||||
|
subparsers.add_parser(
|
||||||
|
name="restart", epilog=DISCLAIMER, help="restart a running jail"
|
||||||
|
).add_argument("name", help="name of the jail")
|
||||||
|
|
||||||
subparsers.add_parser(
|
subparsers.add_parser(
|
||||||
name="shell",
|
name="shell",
|
||||||
epilog=DISCLAIMER,
|
epilog=DISCLAIMER,
|
||||||
|
@ -1382,6 +1415,9 @@ def main():
|
||||||
elif args.subcommand == "start":
|
elif args.subcommand == "start":
|
||||||
sys.exit(start_jail(args.name))
|
sys.exit(start_jail(args.name))
|
||||||
|
|
||||||
|
elif args.subcommand == "restart":
|
||||||
|
sys.exit(restart_jail(args.name))
|
||||||
|
|
||||||
elif args.subcommand == "shell":
|
elif args.subcommand == "shell":
|
||||||
sys.exit(shell_jail(additional_args))
|
sys.exit(shell_jail(additional_args))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue