Add --remove option to disable removal after stop
This commit is contained in:
parent
11bca0af53
commit
6bf57bf761
10
main.py
10
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,6 +130,8 @@ class PodKeeper:
|
|||
except sh.ErrorReturnCode:
|
||||
if not successful_stopped:
|
||||
print(f"Second stop of {self.podname} was not successful!", file=sys.stderr, flush=True)
|
||||
|
||||
if self.remove:
|
||||
try:
|
||||
podman.pod.rm(self.podname)
|
||||
except sh.ErrorReturnCode:
|
||||
|
@ -138,9 +141,10 @@ class PodKeeper:
|
|||
@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)
|
||||
|
|
Loading…
Reference in a new issue