Skip to content

Commit

Permalink
dump
Browse files Browse the repository at this point in the history
  • Loading branch information
yogo1212 committed Sep 25, 2022
1 parent db1861d commit d185c25
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# TODO: podman pod logs --color -n -f pod_testlogs


import signal
import sys
import os
import getpass
Expand Down Expand Up @@ -2067,6 +2068,20 @@ def compose_up(compose, args):
threads.append(thread)
time.sleep(1)

def terminate_signal(sig, frame):
# stop
container_names = [cnt["name"] for cnt in compose.containers]
compose.podman.run([], "stop", ["-i", *container_names])

# don't do this twice
compose.containers = []

old_sigterm = signal.getsignal(signal.SIGTERM)
signal.signal(signal.SIGTERM, terminate_signal)

old_sigint = signal.getsignal(signal.SIGINT)
signal.signal(signal.SIGINT, terminate_signal)

while threads:
to_remove = []
for thread in threads:
Expand All @@ -2082,6 +2097,13 @@ def compose_up(compose, args):
for thread in to_remove:
threads.remove(thread)

signal.signal(signal.SIGTERM, old_sigterm)
signal.signal(signal.SIGINT, old_sigint)

if args.bring_down_on_exit:
# TODO excluded?
# TODO share code with compose_down?


def get_volume_names(compose, cnt):
proj_name = compose.project_name
Expand Down Expand Up @@ -2521,6 +2543,11 @@ def compose_up_parse(parser):
default=None,
help="Return the exit code of the selected service container. Implies --abort-on-container-exit.",
)
parser.add_argument(
"--bring-down-on-exit",
action="store_true",
help="Tear down generated resources on exit. Incompatible with -d.",
)


@cmd_parse(podman_compose, "down")
Expand Down

0 comments on commit d185c25

Please sign in to comment.