Merge pull request #30754 from yongtang/25696-stop-signal

Add `--stop-signal` for `service create` and `service update`
This commit is contained in:
Sebastiaan van Stijn 2017-03-01 18:10:57 +01:00 committed by GitHub
commit decce9cad1
3 changed files with 41 additions and 11 deletions

View File

@ -269,6 +269,7 @@ type serviceOptions struct {
workdir string workdir string
user string user string
groups opts.ListOpts groups opts.ListOpts
stopSignal string
tty bool tty bool
readOnly bool readOnly bool
mounts opts.MountOpt mounts opts.MountOpt
@ -372,17 +373,18 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
}, },
TaskTemplate: swarm.TaskSpec{ TaskTemplate: swarm.TaskSpec{
ContainerSpec: swarm.ContainerSpec{ ContainerSpec: swarm.ContainerSpec{
Image: opts.image, Image: opts.image,
Args: opts.args, Args: opts.args,
Env: currentEnv, Env: currentEnv,
Hostname: opts.hostname, Hostname: opts.hostname,
Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()), Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()),
Dir: opts.workdir, Dir: opts.workdir,
User: opts.user, User: opts.user,
Groups: opts.groups.GetAll(), Groups: opts.groups.GetAll(),
TTY: opts.tty, StopSignal: opts.stopSignal,
ReadOnly: opts.readOnly, TTY: opts.tty,
Mounts: opts.mounts.Value(), ReadOnly: opts.readOnly,
Mounts: opts.mounts.Value(),
DNSConfig: &swarm.DNSConfig{ DNSConfig: &swarm.DNSConfig{
Nameservers: opts.dns.GetAll(), Nameservers: opts.dns.GetAll(),
Search: opts.dnsSearch.GetAll(), Search: opts.dnsSearch.GetAll(),
@ -470,6 +472,9 @@ func addServiceFlags(cmd *cobra.Command, opts *serviceOptions) {
flags.BoolVar(&opts.readOnly, flagReadOnly, false, "Mount the container's root filesystem as read only") flags.BoolVar(&opts.readOnly, flagReadOnly, false, "Mount the container's root filesystem as read only")
flags.SetAnnotation(flagReadOnly, "version", []string{"1.27"}) flags.SetAnnotation(flagReadOnly, "version", []string{"1.27"})
flags.StringVar(&opts.stopSignal, flagStopSignal, "", "Signal to stop the container")
flags.SetAnnotation(flagStopSignal, "version", []string{"1.27"})
} }
const ( const (
@ -523,6 +528,7 @@ const (
flagRestartMaxAttempts = "restart-max-attempts" flagRestartMaxAttempts = "restart-max-attempts"
flagRestartWindow = "restart-window" flagRestartWindow = "restart-window"
flagStopGracePeriod = "stop-grace-period" flagStopGracePeriod = "stop-grace-period"
flagStopSignal = "stop-signal"
flagTTY = "tty" flagTTY = "tty"
flagUpdateDelay = "update-delay" flagUpdateDelay = "update-delay"
flagUpdateFailureAction = "update-failure-action" flagUpdateFailureAction = "update-failure-action"

View File

@ -349,6 +349,8 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
cspec.ReadOnly = readOnly cspec.ReadOnly = readOnly
} }
updateString(flagStopSignal, &cspec.StopSignal)
return nil return nil
} }

View File

@ -441,3 +441,25 @@ func TestUpdateReadOnly(t *testing.T) {
updateService(flags, spec) updateService(flags, spec)
assert.Equal(t, cspec.ReadOnly, false) assert.Equal(t, cspec.ReadOnly, false)
} }
func TestUpdateStopSignal(t *testing.T) {
spec := &swarm.ServiceSpec{}
cspec := &spec.TaskTemplate.ContainerSpec
// Update with --stop-signal=SIGUSR1
flags := newUpdateCommand(nil).Flags()
flags.Set("stop-signal", "SIGUSR1")
updateService(flags, spec)
assert.Equal(t, cspec.StopSignal, "SIGUSR1")
// Update without --stop-signal, no change
flags = newUpdateCommand(nil).Flags()
updateService(flags, spec)
assert.Equal(t, cspec.StopSignal, "SIGUSR1")
// Update with --stop-signal=SIGWINCH
flags = newUpdateCommand(nil).Flags()
flags.Set("stop-signal", "SIGWINCH")
updateService(flags, spec)
assert.Equal(t, cspec.StopSignal, "SIGWINCH")
}