瀏覽代碼

Merge pull request #867 from knutwalker/feature/timeout-flag

Add timeout flag to stop, restart, and up
Ben Firshman 10 年之前
父節點
當前提交
8b5a882459
共有 2 個文件被更改,包括 68 次插入19 次删除
  1. 31 14
      compose/cli/main.py
  2. 37 5
      contrib/completion/bash/docker-compose

+ 31 - 14
compose/cli/main.py

@@ -393,17 +393,29 @@ class TopLevelCommand(Command):
 
         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):
         """
         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):
         """
@@ -422,14 +434,17 @@ class TopLevelCommand(Command):
         Usage: up [options] [SERVICE...]
 
         Options:
-            --allow-insecure-ssl  Allow insecure connections to the docker
-                                  registry
-            -d                    Detached mode: Run containers in the background,
-                                  print new container names.
-            --no-color            Produce monochrome output.
-            --no-deps             Don't start linked services.
-            --no-recreate         If containers already exist, don't recreate them.
-            --no-build            Don't build an image, even if it's missing
+            --allow-insecure-ssl   Allow insecure connections to the docker
+                                   registry
+            -d                     Detached mode: Run containers in the background,
+                                   print new container names.
+            --no-color             Produce monochrome output.
+            --no-deps              Don't start linked services.
+            --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)
+
         """
         insecure_registry = options['--allow-insecure-ssl']
         detached = options['-d']
@@ -445,7 +460,7 @@ class TopLevelCommand(Command):
             start_deps=start_deps,
             recreate=recreate,
             insecure_registry=insecure_registry,
-            detach=options['-d'],
+            detach=detached,
             do_build=not options['--no-build'],
         )
 
@@ -464,7 +479,9 @@ class TopLevelCommand(Command):
                 signal.signal(signal.SIGINT, handler)
 
                 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):

+ 37 - 5
contrib/completion/bash/docker-compose

@@ -1,7 +1,7 @@
 #!bash
 #
 # bash completion for docker-compose
-# 
+#
 # This work is based on the completion for the docker command.
 #
 # This script provides completion of:
@@ -196,7 +196,20 @@ _docker-compose_pull() {
 
 
 _docker-compose_restart() {
-	__docker-compose_services_running
+	case "$prev" in
+		-t | --timeout)
+			return
+			;;
+	esac
+
+	case "$cur" in
+		-*)
+			COMPREPLY=( $( compgen -W "-t --timeout" -- "$cur" ) )
+			;;
+		*)
+			__docker-compose_services_running
+			;;
+	esac
 }
 
 
@@ -221,7 +234,7 @@ _docker-compose_run() {
 			;;
 		--entrypoint)
 			return
-			;;	
+			;;
 	esac
 
 	case "$cur" in
@@ -254,14 +267,33 @@ _docker-compose_start() {
 
 
 _docker-compose_stop() {
-	__docker-compose_services_running
+	case "$prev" in
+		-t | --timeout)
+			return
+			;;
+	esac
+
+	case "$cur" in
+		-*)
+			COMPREPLY=( $( compgen -W "-t --timeout" -- "$cur" ) )
+			;;
+		*)
+			__docker-compose_services_running
+			;;
+	esac
 }
 
 
 _docker-compose_up() {
+	case "$prev" in
+		-t | --timeout)
+			return
+			;;
+	esac
+
 	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