Add --remove option to disable removal after stop
This commit is contained in:
parent
11bca0af53
commit
6bf57bf761
18
main.py
18
main.py
|
@ -19,9 +19,10 @@ sdnotify = sh.Command("systemd-notify")
|
||||||
|
|
||||||
|
|
||||||
class PodKeeper:
|
class PodKeeper:
|
||||||
def __init__(self, network, replace, identifier):
|
def __init__(self, network, replace, remove, identifier):
|
||||||
self.podnet_args = ("--network", network) if network else ()
|
self.podnet_args = ("--network", network) if network else ()
|
||||||
self.replace = replace
|
self.replace = replace
|
||||||
|
self.remove = remove
|
||||||
identifier_path = pathlib.PurePath(identifier)
|
identifier_path = pathlib.PurePath(identifier)
|
||||||
if len(identifier_path.parts) != 1:
|
if len(identifier_path.parts) != 1:
|
||||||
raise ValueError(f"identifier has path parts: {identifier_path}")
|
raise ValueError(f"identifier has path parts: {identifier_path}")
|
||||||
|
@ -129,18 +130,21 @@ class PodKeeper:
|
||||||
except sh.ErrorReturnCode:
|
except sh.ErrorReturnCode:
|
||||||
if not successful_stopped:
|
if not successful_stopped:
|
||||||
print(f"Second stop of {self.podname} was not successful!", file=sys.stderr, flush=True)
|
print(f"Second stop of {self.podname} was not successful!", file=sys.stderr, flush=True)
|
||||||
try:
|
|
||||||
podman.pod.rm(self.podname)
|
if self.remove:
|
||||||
except sh.ErrorReturnCode:
|
try:
|
||||||
print(f"Removal of {self.podname} was not successful!", file=sys.stderr, flush=True)
|
podman.pod.rm(self.podname)
|
||||||
|
except sh.ErrorReturnCode:
|
||||||
|
print(f"Removal of {self.podname} was not successful!", file=sys.stderr, flush=True)
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--network", default="brodge", help="Network for the created pod")
|
@click.option("--network", default="brodge", help="Network for the created pod")
|
||||||
@click.option("--replace", default=True, help="Replace previously running pod with the same name")
|
@click.option("--replace", default=True, help="Replace previously running pod with the same name")
|
||||||
|
@click.option("--remove", default=True, help="Remove pod after stopping")
|
||||||
@click.argument("identifier")
|
@click.argument("identifier")
|
||||||
def main(network, replace, identifier):
|
def main(network, replace, remove, identifier):
|
||||||
keeper = PodKeeper(network, replace, identifier)
|
keeper = PodKeeper(network, replace, remove, identifier)
|
||||||
|
|
||||||
signal(SIGINT, keeper.destroy)
|
signal(SIGINT, keeper.destroy)
|
||||||
signal(SIGTERM, keeper.destroy)
|
signal(SIGTERM, keeper.destroy)
|
||||||
|
|
Loading…
Reference in a new issue