From 6bf57bf7619ee4204b1b02f27eda25bd0c95261c Mon Sep 17 00:00:00 2001 From: Benedikt Ziemons Date: Wed, 30 Dec 2020 20:15:02 +0100 Subject: [PATCH] Add --remove option to disable removal after stop --- main.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index bd49cd9..9c686c9 100644 --- a/main.py +++ b/main.py @@ -19,9 +19,10 @@ sdnotify = sh.Command("systemd-notify") class PodKeeper: - def __init__(self, network, replace, identifier): + def __init__(self, network, replace, remove, identifier): self.podnet_args = ("--network", network) if network else () self.replace = replace + self.remove = remove identifier_path = pathlib.PurePath(identifier) if len(identifier_path.parts) != 1: raise ValueError(f"identifier has path parts: {identifier_path}") @@ -129,18 +130,21 @@ class PodKeeper: except sh.ErrorReturnCode: if not successful_stopped: print(f"Second stop of {self.podname} was not successful!", file=sys.stderr, flush=True) - try: - podman.pod.rm(self.podname) - except sh.ErrorReturnCode: - print(f"Removal of {self.podname} was not successful!", file=sys.stderr, flush=True) + + if self.remove: + try: + 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.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("--remove", default=True, help="Remove pod after stopping") @click.argument("identifier") -def main(network, replace, identifier): - keeper = PodKeeper(network, replace, identifier) +def main(network, replace, remove, identifier): + keeper = PodKeeper(network, replace, remove, identifier) signal(SIGINT, keeper.destroy) signal(SIGTERM, keeper.destroy)