mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
Stop other containers if the flag is set.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
bf2bf21720
commit
15b2094bad
@ -5,7 +5,6 @@ import sys
|
|||||||
from itertools import cycle
|
from itertools import cycle
|
||||||
|
|
||||||
from . import colors
|
from . import colors
|
||||||
from . import signals
|
|
||||||
from .multiplexer import Multiplexer
|
from .multiplexer import Multiplexer
|
||||||
from compose import utils
|
from compose import utils
|
||||||
from compose.utils import split_buffer
|
from compose.utils import split_buffer
|
||||||
@ -42,7 +41,7 @@ class LogPrinter(object):
|
|||||||
for color_func, container in zip(color_funcs, self.containers):
|
for color_func, container in zip(color_funcs, self.containers):
|
||||||
generator_func = get_log_generator(container)
|
generator_func = get_log_generator(container)
|
||||||
prefix = color_func(build_log_prefix(container, prefix_width))
|
prefix = color_func(build_log_prefix(container, prefix_width))
|
||||||
yield generator_func(container, prefix, color_func, self.cascade_stop)
|
yield generator_func(container, prefix, color_func)
|
||||||
|
|
||||||
|
|
||||||
def build_log_prefix(container, prefix_width):
|
def build_log_prefix(container, prefix_width):
|
||||||
@ -65,7 +64,7 @@ def get_log_generator(container):
|
|||||||
return build_no_log_generator
|
return build_no_log_generator
|
||||||
|
|
||||||
|
|
||||||
def build_no_log_generator(container, prefix, color_func, cascade_stop):
|
def build_no_log_generator(container, prefix, color_func):
|
||||||
"""Return a generator that prints a warning about logs and waits for
|
"""Return a generator that prints a warning about logs and waits for
|
||||||
container to exit.
|
container to exit.
|
||||||
"""
|
"""
|
||||||
@ -73,11 +72,9 @@ def build_no_log_generator(container, prefix, color_func, cascade_stop):
|
|||||||
prefix,
|
prefix,
|
||||||
container.log_driver)
|
container.log_driver)
|
||||||
yield color_func(wait_on_exit(container))
|
yield color_func(wait_on_exit(container))
|
||||||
if cascade_stop:
|
|
||||||
raise signals.CascadeStopException()
|
|
||||||
|
|
||||||
|
|
||||||
def build_log_generator(container, prefix, color_func, cascade_stop):
|
def build_log_generator(container, prefix, color_func):
|
||||||
# if the container doesn't have a log_stream we need to attach to container
|
# if the container doesn't have a log_stream we need to attach to container
|
||||||
# before log printer starts running
|
# before log printer starts running
|
||||||
if container.log_stream is None:
|
if container.log_stream is None:
|
||||||
@ -89,8 +86,6 @@ def build_log_generator(container, prefix, color_func, cascade_stop):
|
|||||||
for line in line_generator:
|
for line in line_generator:
|
||||||
yield prefix + line
|
yield prefix + line
|
||||||
yield color_func(wait_on_exit(container))
|
yield color_func(wait_on_exit(container))
|
||||||
if cascade_stop:
|
|
||||||
raise signals.CascadeStopException()
|
|
||||||
|
|
||||||
|
|
||||||
def wait_on_exit(container):
|
def wait_on_exit(container):
|
||||||
|
@ -662,6 +662,10 @@ class TopLevelCommand(DocoptCommand):
|
|||||||
print("Attaching to", list_containers(log_printer.containers))
|
print("Attaching to", list_containers(log_printer.containers))
|
||||||
log_printer.run()
|
log_printer.run()
|
||||||
|
|
||||||
|
if cascade_stop:
|
||||||
|
print("Aborting on container exit...")
|
||||||
|
project.stop(service_names=service_names, timeout=timeout)
|
||||||
|
|
||||||
def version(self, project, options):
|
def version(self, project, options):
|
||||||
"""
|
"""
|
||||||
Show version informations
|
Show version informations
|
||||||
@ -774,9 +778,6 @@ def up_shutdown_context(project, service_names, timeout, detached):
|
|||||||
except signals.ShutdownException:
|
except signals.ShutdownException:
|
||||||
print("Gracefully stopping... (press Ctrl+C again to force)")
|
print("Gracefully stopping... (press Ctrl+C again to force)")
|
||||||
project.stop(service_names=service_names, timeout=timeout)
|
project.stop(service_names=service_names, timeout=timeout)
|
||||||
except signals.CascadeStopException:
|
|
||||||
print("Aborting on container exit... (press Ctrl+C to force)")
|
|
||||||
project.stop(service_names=service_names, timeout=timeout)
|
|
||||||
except signals.ShutdownException:
|
except signals.ShutdownException:
|
||||||
project.kill(service_names=service_names)
|
project.kill(service_names=service_names)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
@ -8,10 +8,6 @@ class ShutdownException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CascadeStopException(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def shutdown(signal, frame):
|
def shutdown(signal, frame):
|
||||||
raise ShutdownException()
|
raise ShutdownException()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user