mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-28 20:13:33 +00:00
chore: 'uc stop' - make --timeout default explicit, update flag and long descriptions
This commit is contained in:
@@ -19,7 +19,10 @@ func NewStartCommand(groupID string) *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "start SERVICE [SERVICE...]",
|
Use: "start SERVICE [SERVICE...]",
|
||||||
Short: "Start one or more services.",
|
Short: "Start one or more services.",
|
||||||
Long: "Start one or more services.",
|
Long: `Start one or more previously stopped services.
|
||||||
|
|
||||||
|
Starts all containers of the specified service(s) across all machines in the cluster.
|
||||||
|
Services can be specified by name or ID.`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
uncli := cmd.Context().Value("cli").(*cli.CLI)
|
uncli := cmd.Context().Value("cli").(*cli.CLI)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import (
|
|||||||
type stopOptions struct {
|
type stopOptions struct {
|
||||||
services []string
|
services []string
|
||||||
signal string
|
signal string
|
||||||
timeoutChanged bool
|
|
||||||
timeout int
|
timeout int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,18 +22,24 @@ func NewStopCommand(groupID string) *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "stop SERVICE [SERVICE...]",
|
Use: "stop SERVICE [SERVICE...]",
|
||||||
Short: "Stop one or more services.",
|
Short: "Stop one or more services.",
|
||||||
Long: "Stop one or more services.",
|
Long: `Stop one or more running services.
|
||||||
|
|
||||||
|
Gracefully stops all containers of the specified service(s) across all machines in the cluster.
|
||||||
|
Services can be specified by name or ID. Stopped services can be restarted with 'uc start'.`,
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
uncli := cmd.Context().Value("cli").(*cli.CLI)
|
uncli := cmd.Context().Value("cli").(*cli.CLI)
|
||||||
opts.services = args
|
opts.services = args
|
||||||
opts.timeoutChanged = cmd.Flags().Changed("timeout")
|
|
||||||
return stop(cmd.Context(), uncli, opts)
|
return stop(cmd.Context(), uncli, opts)
|
||||||
},
|
},
|
||||||
GroupID: groupID,
|
GroupID: groupID,
|
||||||
}
|
}
|
||||||
cmd.Flags().StringVarP(&opts.signal, "signal", "s", "", "Signal to send to the container")
|
cmd.Flags().StringVarP(&opts.signal, "signal", "s", "",
|
||||||
cmd.Flags().IntVarP(&opts.timeout, "timeout", "t", 0, "Seconds to wait before killing the container")
|
"Signal to send to each container's main process.\n"+
|
||||||
|
"Can be a signal name (SIGTERM, SIGINT, SIGHUP, etc.) or a number. (default SIGTERM)")
|
||||||
|
cmd.Flags().IntVarP(&opts.timeout, "timeout", "t", 10,
|
||||||
|
"Seconds to wait for each container to stop gracefully before forcibly killing it with SIGKILL.\n"+
|
||||||
|
"Use -1 to wait indefinitely.")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,9 +52,7 @@ func stop(ctx context.Context, uncli *cli.CLI, opts stopOptions) error {
|
|||||||
|
|
||||||
stopOpts := container.StopOptions{
|
stopOpts := container.StopOptions{
|
||||||
Signal: opts.signal,
|
Signal: opts.signal,
|
||||||
}
|
Timeout: &opts.timeout,
|
||||||
if opts.timeoutChanged {
|
|
||||||
stopOpts.Timeout = &opts.timeout
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range opts.services {
|
for _, s := range opts.services {
|
||||||
|
|||||||
Reference in New Issue
Block a user