// SignalService sends the given signal to the given service (by name) of the remote caretakerd instance. func (instance *Client) SignalService(name string, s values.Signal) error { payload := map[string]string{ "signal": s.String(), } err := instance.post("service/"+name+"/signal", &payload) if _, ok := err.(ConflictError); ok { return ConflictError{error: "Service '" + name + "' is down."} } return err }
func createSignalServiceCommand(commonClientFlags []cli.Flag, clientFactory *client.Factory) cli.Command { return cli.Command{ Name: "serviceSignal", Flags: commonClientFlags, ArgsUsage: "<service name> <signal>", Aliases: []string{"signal"}, Usage: "Send a signal to service.", Before: ensureServiceNameAndSignalArgument, Action: actionWrapper(clientFactory, func(context *cli.Context, client *client.Client) error { args := context.Args() name := args[0] var sig values.Signal err := sig.Set(args[1]) if err != nil { return UsageError{error: err.Error()} } return client.SignalService(name, sig) }), OnUsageError: onUsageErrorFor("serviceSignal"), } }
func ensureServiceNameAndSignalArgument(context *cli.Context) error { err := baseControlEnsure(context) if err != nil { return err } args := context.Args() if (len(args) <= 0) || (len(strings.TrimSpace(args[0])) == 0) { return UsageError{error: "There is no service name provided."} } if (len(args) <= 1) || (len(strings.TrimSpace(args[1])) == 0) { return UsageError{error: "There is no signal provided."} } var sig values.Signal err = sig.Set(args[1]) if err != nil { return UsageError{error: err.Error()} } if len(args) > 2 { return UsageError{error: "There are only two arguments allowed."} } return nil }