diff --git a/cmd/compose/down.go b/cmd/compose/down.go index 8a997b256..44dea5063 100644 --- a/cmd/compose/down.go +++ b/cmd/compose/down.go @@ -63,7 +63,7 @@ func downCommand(p *ProjectOptions, backend api.Service) *cobra.Command { flags := downCmd.Flags() removeOrphans := utils.StringToBool(os.Getenv(ComposeRemoveOrphans)) flags.BoolVar(&opts.removeOrphans, "remove-orphans", removeOrphans, "Remove containers for services not defined in the Compose file.") - flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds") + flags.IntVarP(&opts.timeout, "timeout", "t", 0, "Specify a shutdown timeout in seconds") flags.BoolVarP(&opts.volumes, "volumes", "v", false, `Remove named volumes declared in the "volumes" section of the Compose file and anonymous volumes attached to containers.`) flags.StringVar(&opts.images, "rmi", "", `Remove images used by services. "local" remove only images that don't have a custom tag ("local"|"all")`) flags.SetNormalizeFunc(func(f *pflag.FlagSet, name string) pflag.NormalizedName { diff --git a/cmd/compose/restart.go b/cmd/compose/restart.go index 024676001..90848cd44 100644 --- a/cmd/compose/restart.go +++ b/cmd/compose/restart.go @@ -28,8 +28,9 @@ import ( type restartOptions struct { *ProjectOptions - timeout int - noDeps bool + timeChanged bool + timeout int + noDeps bool } func restartCommand(p *ProjectOptions, backend api.Service) *cobra.Command { @@ -39,13 +40,16 @@ func restartCommand(p *ProjectOptions, backend api.Service) *cobra.Command { restartCmd := &cobra.Command{ Use: "restart [OPTIONS] [SERVICE...]", Short: "Restart service containers", + PreRun: func(cmd *cobra.Command, args []string) { + opts.timeChanged = cmd.Flags().Changed("timeout") + }, RunE: Adapt(func(ctx context.Context, args []string) error { return runRestart(ctx, backend, opts, args) }), ValidArgsFunction: completeServiceNames(p), } flags := restartCmd.Flags() - flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds") + flags.IntVarP(&opts.timeout, "timeout", "t", 0, "Specify a shutdown timeout in seconds") flags.BoolVar(&opts.noDeps, "no-deps", false, "Don't restart dependent services.") return restartCmd @@ -57,6 +61,12 @@ func runRestart(ctx context.Context, backend api.Service, opts restartOptions, s return err } + var timeout *time.Duration + if opts.timeChanged { + timeoutValue := time.Duration(opts.timeout) * time.Second + timeout = &timeoutValue + } + if opts.noDeps { err := project.ForServices(services, types.IgnoreDependencies) if err != nil { @@ -64,9 +74,8 @@ func runRestart(ctx context.Context, backend api.Service, opts restartOptions, s } } - timeout := time.Duration(opts.timeout) * time.Second return backend.Restart(ctx, name, api.RestartOptions{ - Timeout: &timeout, + Timeout: timeout, Services: services, Project: project, }) diff --git a/cmd/compose/stop.go b/cmd/compose/stop.go index cd25823ee..12ae59d8f 100644 --- a/cmd/compose/stop.go +++ b/cmd/compose/stop.go @@ -47,7 +47,7 @@ func stopCommand(p *ProjectOptions, backend api.Service) *cobra.Command { ValidArgsFunction: completeServiceNames(p), } flags := cmd.Flags() - flags.IntVarP(&opts.timeout, "timeout", "t", 10, "Specify a shutdown timeout in seconds") + flags.IntVarP(&opts.timeout, "timeout", "t", 0, "Specify a shutdown timeout in seconds") return cmd } diff --git a/cmd/compose/up.go b/cmd/compose/up.go index 6894367d0..9eb254855 100644 --- a/cmd/compose/up.go +++ b/cmd/compose/up.go @@ -78,7 +78,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob Short: "Create and start containers", PreRunE: AdaptCmd(func(ctx context.Context, cmd *cobra.Command, args []string) error { create.pullChanged = cmd.Flags().Changed("pull") - create.timeChanged = cmd.Flags().Changed("waitTimeout") + create.timeChanged = cmd.Flags().Changed("timeout") return validateFlags(&up, &create) }), RunE: p.WithServices(func(ctx context.Context, project *types.Project, services []string) error { @@ -104,7 +104,7 @@ func upCommand(p *ProjectOptions, streams api.Streams, backend api.Service) *cob flags.BoolVar(&up.noStart, "no-start", false, "Don't start the services after creating them.") flags.BoolVar(&up.cascadeStop, "abort-on-container-exit", false, "Stops all containers if any container was stopped. Incompatible with -d") flags.StringVar(&up.exitCodeFrom, "exit-code-from", "", "Return the exit code of the selected service container. Implies --abort-on-container-exit") - flags.IntVarP(&create.timeout, "timeout", "t", 10, "Use this timeout in seconds for container shutdown when attached or when containers are already running.") + flags.IntVarP(&create.timeout, "timeout", "t", 0, "Use this timeout in seconds for container shutdown when attached or when containers are already running.") flags.BoolVar(&up.timestamp, "timestamps", false, "Show timestamps.") flags.BoolVar(&up.noDeps, "no-deps", false, "Don't start linked services.") flags.BoolVar(&create.recreateDeps, "always-recreate-deps", false, "Recreate dependent containers. Incompatible with --no-recreate.") diff --git a/docs/reference/compose_down.md b/docs/reference/compose_down.md index 3f80f9b77..92d10389d 100644 --- a/docs/reference/compose_down.md +++ b/docs/reference/compose_down.md @@ -10,7 +10,7 @@ Stop and remove containers, networks | `--dry-run` | | | Execute command in dry run mode | | `--remove-orphans` | | | Remove containers for services not defined in the Compose file. | | `--rmi` | `string` | | Remove images used by services. "local" remove only images that don't have a custom tag ("local"\|"all") | -| `-t`, `--timeout` | `int` | `10` | Specify a shutdown timeout in seconds | +| `-t`, `--timeout` | `int` | `0` | Specify a shutdown timeout in seconds | | `-v`, `--volumes` | | | Remove named volumes declared in the "volumes" section of the Compose file and anonymous volumes attached to containers. | diff --git a/docs/reference/compose_restart.md b/docs/reference/compose_restart.md index 94039c3e7..973851ab5 100644 --- a/docs/reference/compose_restart.md +++ b/docs/reference/compose_restart.md @@ -9,7 +9,7 @@ Restart service containers |:------------------|:------|:--------|:--------------------------------------| | `--dry-run` | | | Execute command in dry run mode | | `--no-deps` | | | Don't restart dependent services. | -| `-t`, `--timeout` | `int` | `10` | Specify a shutdown timeout in seconds | +| `-t`, `--timeout` | `int` | `0` | Specify a shutdown timeout in seconds | diff --git a/docs/reference/compose_stop.md b/docs/reference/compose_stop.md index de6a0da3b..e7cf92a80 100644 --- a/docs/reference/compose_stop.md +++ b/docs/reference/compose_stop.md @@ -8,7 +8,7 @@ Stop services | Name | Type | Default | Description | |:------------------|:------|:--------|:--------------------------------------| | `--dry-run` | | | Execute command in dry run mode | -| `-t`, `--timeout` | `int` | `10` | Specify a shutdown timeout in seconds | +| `-t`, `--timeout` | `int` | `0` | Specify a shutdown timeout in seconds | diff --git a/docs/reference/compose_up.md b/docs/reference/compose_up.md index 70f416362..836d80d25 100644 --- a/docs/reference/compose_up.md +++ b/docs/reference/compose_up.md @@ -28,7 +28,7 @@ Create and start containers | `--remove-orphans` | | | Remove containers for services not defined in the Compose file. | | `-V`, `--renew-anon-volumes` | | | Recreate anonymous volumes instead of retrieving data from the previous containers. | | `--scale` | `stringArray` | | Scale SERVICE to NUM instances. Overrides the `scale` setting in the Compose file if present. | -| `-t`, `--timeout` | `int` | `10` | Use this timeout in seconds for container shutdown when attached or when containers are already running. | +| `-t`, `--timeout` | `int` | `0` | Use this timeout in seconds for container shutdown when attached or when containers are already running. | | `--timestamps` | | | Show timestamps. | | `--wait` | | | Wait for services to be running\|healthy. Implies detached mode. | | `--wait-timeout` | `int` | `0` | timeout waiting for application to be running\|healthy. | diff --git a/docs/reference/docker_compose_down.yaml b/docs/reference/docker_compose_down.yaml index 6c6724780..69b802f0f 100644 --- a/docs/reference/docker_compose_down.yaml +++ b/docs/reference/docker_compose_down.yaml @@ -41,7 +41,7 @@ options: - option: timeout shorthand: t value_type: int - default_value: "10" + default_value: "0" description: Specify a shutdown timeout in seconds deprecated: false hidden: false diff --git a/docs/reference/docker_compose_restart.yaml b/docs/reference/docker_compose_restart.yaml index b5ecfb289..055daedd1 100644 --- a/docs/reference/docker_compose_restart.yaml +++ b/docs/reference/docker_compose_restart.yaml @@ -28,7 +28,7 @@ options: - option: timeout shorthand: t value_type: int - default_value: "10" + default_value: "0" description: Specify a shutdown timeout in seconds deprecated: false hidden: false diff --git a/docs/reference/docker_compose_stop.yaml b/docs/reference/docker_compose_stop.yaml index 9cc5258b9..f7870be4f 100644 --- a/docs/reference/docker_compose_stop.yaml +++ b/docs/reference/docker_compose_stop.yaml @@ -9,7 +9,7 @@ options: - option: timeout shorthand: t value_type: int - default_value: "10" + default_value: "0" description: Specify a shutdown timeout in seconds deprecated: false hidden: false diff --git a/docs/reference/docker_compose_up.yaml b/docs/reference/docker_compose_up.yaml index 1c46ca79a..b59af8496 100644 --- a/docs/reference/docker_compose_up.yaml +++ b/docs/reference/docker_compose_up.yaml @@ -234,7 +234,7 @@ options: - option: timeout shorthand: t value_type: int - default_value: "10" + default_value: "0" description: | Use this timeout in seconds for container shutdown when attached or when containers are already running. deprecated: false