Add timeout flag to stop, restart, and up

The commands `stop`, `restart`, and `up` now support a flag `--timeout`.
It represents the number of seconds to give the services to comply to
the command. In case of `up`, this is only relevant if running in
attached mode.

Signed-off-by: Paul Horn <knutwalker@gmail.com>
This commit is contained in:
Paul Horn 2015-01-21 00:22:30 +01:00
parent 9e9a66f0f8
commit 2534a0964f
2 changed files with 68 additions and 19 deletions

View File

@ -387,17 +387,29 @@ class TopLevelCommand(Command):
They can be started again with `docker-compose start`. They can be started again with `docker-compose start`.
Usage: stop [SERVICE...] Usage: stop [options] [SERVICE...]
Options:
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)
""" """
project.stop(service_names=options['SERVICE']) timeout = options.get('--timeout')
params = {} if timeout is None else {'timeout': int(timeout)}
project.stop(service_names=options['SERVICE'], **params)
def restart(self, project, options): def restart(self, project, options):
""" """
Restart running containers. Restart running containers.
Usage: restart [SERVICE...] Usage: restart [options] [SERVICE...]
Options:
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)
""" """
project.restart(service_names=options['SERVICE']) timeout = options.get('--timeout')
params = {} if timeout is None else {'timeout': int(timeout)}
project.restart(service_names=options['SERVICE'], **params)
def up(self, project, options): def up(self, project, options):
""" """
@ -424,6 +436,9 @@ class TopLevelCommand(Command):
--no-deps Don't start linked services. --no-deps Don't start linked services.
--no-recreate If containers already exist, don't recreate them. --no-recreate If containers already exist, don't recreate them.
--no-build Don't build an image, even if it's missing --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)
""" """
insecure_registry = options['--allow-insecure-ssl'] insecure_registry = options['--allow-insecure-ssl']
detached = options['-d'] detached = options['-d']
@ -439,7 +454,7 @@ class TopLevelCommand(Command):
start_links=start_links, start_links=start_links,
recreate=recreate, recreate=recreate,
insecure_registry=insecure_registry, insecure_registry=insecure_registry,
detach=options['-d'], detach=detached,
do_build=not options['--no-build'], do_build=not options['--no-build'],
) )
@ -458,7 +473,9 @@ class TopLevelCommand(Command):
signal.signal(signal.SIGINT, handler) signal.signal(signal.SIGINT, handler)
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 = options.get('--timeout')
params = {} if timeout is None else {'timeout': int(timeout)}
project.stop(service_names=service_names, **params)
def list_containers(containers): def list_containers(containers):

View File

@ -196,7 +196,20 @@ _docker-compose_pull() {
_docker-compose_restart() { _docker-compose_restart() {
case "$prev" in
-t | --timeout)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "-t --timeout" -- "$cur" ) )
;;
*)
__docker-compose_services_running __docker-compose_services_running
;;
esac
} }
@ -254,14 +267,33 @@ _docker-compose_start() {
_docker-compose_stop() { _docker-compose_stop() {
case "$prev" in
-t | --timeout)
return
;;
esac
case "$cur" in
-*)
COMPREPLY=( $( compgen -W "-t --timeout" -- "$cur" ) )
;;
*)
__docker-compose_services_running __docker-compose_services_running
;;
esac
} }
_docker-compose_up() { _docker-compose_up() {
case "$prev" in
-t | --timeout)
return
;;
esac
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "--allow-insecure-ssl -d --no-build --no-color --no-deps --no-recreate" -- "$cur" ) ) COMPREPLY=( $( compgen -W "--allow-insecure-ssl -d --no-build --no-color --no-deps --no-recreate -t --timeout" -- "$cur" ) )
;; ;;
*) *)
__docker-compose_services_all __docker-compose_services_all