Extend up -t to pass timeout to stop running containers

Signed-off-by: Travis Thieman <travis.thieman@gmail.com>
This commit is contained in:
Travis Thieman
2015-05-28 09:28:02 -04:00
committed by Daniel Nephin
parent 60351a8e07
commit c24d5380e6
5 changed files with 38 additions and 9 deletions

View File

@@ -439,9 +439,9 @@ class TopLevelCommand(Command):
image needs to be updated. (EXPERIMENTAL)
--no-recreate If containers already exist, don't recreate them.
--no-build Don't build an image, even if it's missing
-t, --timeout TIMEOUT When attached, use this timeout in seconds
for the shutdown. (default: 10)
-t, --timeout TIMEOUT Use this timeout in seconds for container shutdown
when attached or when containers are already
running. (default: 10)
"""
insecure_registry = options['--allow-insecure-ssl']
detached = options['-d']
@@ -452,6 +452,7 @@ class TopLevelCommand(Command):
allow_recreate = not options['--no-recreate']
smart_recreate = options['--x-smart-recreate']
service_names = options['SERVICE']
timeout = int(options['--timeout']) if options['--timeout'] is not None else None
project.up(
service_names=service_names,
@@ -460,6 +461,7 @@ class TopLevelCommand(Command):
smart_recreate=smart_recreate,
insecure_registry=insecure_registry,
do_build=not options['--no-build'],
timeout=timeout
)
to_attach = [c for s in project.get_services(service_names) for c in s.containers()]
@@ -477,8 +479,7 @@ class TopLevelCommand(Command):
signal.signal(signal.SIGINT, handler)
print("Gracefully stopping... (press Ctrl+C again to force)")
timeout = options.get('--timeout')
params = {} if timeout is None else {'timeout': int(timeout)}
params = {} if timeout is None else {'timeout': timeout}
project.stop(service_names=service_names, **params)
def migrate_to_labels(self, project, _options):

View File

@@ -211,7 +211,8 @@ class Project(object):
allow_recreate=True,
smart_recreate=False,
insecure_registry=False,
do_build=True):
do_build=True,
timeout=None):
services = self.get_services(service_names, include_deps=start_deps)
@@ -228,6 +229,7 @@ class Project(object):
plans[service.name],
insecure_registry=insecure_registry,
do_build=do_build,
timeout=timeout
)
]

View File

@@ -311,7 +311,8 @@ class Service(object):
def execute_convergence_plan(self,
plan,
insecure_registry=False,
do_build=True):
do_build=True,
timeout=None):
(action, containers) = plan
if action == 'create':
@@ -328,6 +329,7 @@ class Service(object):
self.recreate_container(
c,
insecure_registry=insecure_registry,
timeout=timeout
)
for c in containers
]
@@ -349,7 +351,8 @@ class Service(object):
def recreate_container(self,
container,
insecure_registry=False):
insecure_registry=False,
timeout=None):
"""Recreate a container.
The original container is renamed to a temporary name so that data
@@ -358,7 +361,8 @@ class Service(object):
"""
log.info("Recreating %s..." % container.name)
try:
container.stop()
stop_params = {} if timeout is None else {'timeout': timeout}
container.stop(**stop_params)
except APIError as e:
if (e.response.status_code == 500
and e.explanation