Fix #4504 Respect timeout option when starting/stopping/restarting containers.

pull/18777/head
shaung 8 years ago committed by Matt Clay
parent c0c5b9a50a
commit bcbeed244b

@ -466,9 +466,11 @@ try:
from compose.cli.command import project_from_options from compose.cli.command import project_from_options
from compose.service import ConvergenceStrategy from compose.service import ConvergenceStrategy
from compose.cli.main import convergence_strategy_from_opts, build_action_from_opts, image_type_from_opt from compose.cli.main import convergence_strategy_from_opts, build_action_from_opts, image_type_from_opt
from compose.const import DEFAULT_TIMEOUT
except ImportError as exc: except ImportError as exc:
HAS_COMPOSE = False HAS_COMPOSE = False
HAS_COMPOSE_EXC = str(exc) HAS_COMPOSE_EXC = str(exc)
DEFAULT_TIMEOUT = 10
from ansible.module_utils.docker_common import * from ansible.module_utils.docker_common import *
@ -653,7 +655,8 @@ class ContainerManager(DockerBaseClass):
strategy=converge, strategy=converge,
do_build=do_build, do_build=do_build,
detached=detached, detached=detached,
remove_orphans=self.remove_orphans) remove_orphans=self.remove_orphans,
timeout=self.timeout)
except Exception as exc: except Exception as exc:
self.client.fail("Error starting project - %s" % str(exc)) self.client.fail("Error starting project - %s" % str(exc))
@ -828,7 +831,7 @@ class ContainerManager(DockerBaseClass):
if not self.check_mode and result['changed']: if not self.check_mode and result['changed']:
try: try:
self.project.stop(service_names=service_names) self.project.stop(service_names=service_names, timeout=self.timeout)
except Exception as exc: except Exception as exc:
self.client.fail("Error stopping services for %s - %s" % (self.project.name, str(exc))) self.client.fail("Error stopping services for %s - %s" % (self.project.name, str(exc)))
@ -855,7 +858,7 @@ class ContainerManager(DockerBaseClass):
if not self.check_mode and result['changed']: if not self.check_mode and result['changed']:
try: try:
self.project.restart(service_names=service_names) self.project.restart(service_names=service_names, timeout=self.timeout)
except Exception as exc: except Exception as exc:
self.client.fail("Error restarting services for %s - %s" % (self.project.name, str(exc))) self.client.fail("Error restarting services for %s - %s" % (self.project.name, str(exc)))
@ -903,7 +906,8 @@ def main():
dependencies=dict(type='bool', default=True), dependencies=dict(type='bool', default=True),
pull=dict(type='bool', default=False), pull=dict(type='bool', default=False),
nocache=dict(type='bool', default=False), nocache=dict(type='bool', default=False),
debug=dict(type='bool', default=False) debug=dict(type='bool', default=False),
timeout=dict(type='int', default=DEFAULT_TIMEOUT)
) )
mutually_exclusive = [ mutually_exclusive = [

Loading…
Cancel
Save