2013-12-19 19:22:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-11-24 19:05:11 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2015-03-30 21:50:45 +00:00
|
|
|
"syscall"
|
2014-11-24 19:05:11 +00:00
|
|
|
|
2013-12-19 19:22:08 +00:00
|
|
|
"github.com/hashicorp/consul/command"
|
2013-12-19 20:18:06 +00:00
|
|
|
"github.com/hashicorp/consul/command/agent"
|
2017-02-08 00:16:33 +00:00
|
|
|
"github.com/hashicorp/consul/command/base"
|
2016-11-03 00:27:49 +00:00
|
|
|
"github.com/hashicorp/consul/version"
|
2013-12-19 19:22:08 +00:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
2014-11-22 17:44:23 +00:00
|
|
|
// Commands is the mapping of all the available Consul commands.
|
2013-12-19 19:22:08 +00:00
|
|
|
var Commands map[string]cli.CommandFactory
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
ui := &cli.BasicUi{Writer: os.Stdout}
|
|
|
|
|
|
|
|
Commands = map[string]cli.CommandFactory{
|
2013-12-19 20:18:06 +00:00
|
|
|
"agent": func() (cli.Command, error) {
|
|
|
|
return &agent.Command{
|
2017-02-25 02:11:05 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetNone,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2016-11-03 00:27:49 +00:00
|
|
|
Revision: version.GitCommit,
|
|
|
|
Version: version.Version,
|
|
|
|
VersionPrerelease: version.VersionPrerelease,
|
|
|
|
HumanVersion: version.GetHumanVersion(),
|
2016-07-20 01:38:15 +00:00
|
|
|
ShutdownCh: make(chan struct{}),
|
2013-12-19 20:18:06 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2015-05-04 18:41:19 +00:00
|
|
|
"configtest": func() (cli.Command, error) {
|
|
|
|
return &command.ConfigTestCommand{
|
2017-02-08 00:16:33 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetNone,
|
2017-02-07 01:50:51 +00:00
|
|
|
Ui: ui,
|
|
|
|
},
|
2015-05-04 18:41:19 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-08-28 23:40:31 +00:00
|
|
|
"event": func() (cli.Command, error) {
|
|
|
|
return &command.EventCommand{
|
2017-02-08 21:56:58 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2014-08-28 23:40:31 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-09-01 04:50:41 +00:00
|
|
|
"exec": func() (cli.Command, error) {
|
|
|
|
return &command.ExecCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
2017-02-08 21:56:58 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2014-09-01 04:50:41 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-31 21:06:33 +00:00
|
|
|
"force-leave": func() (cli.Command, error) {
|
|
|
|
return &command.ForceLeaveCommand{
|
2017-02-08 00:16:33 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
2017-02-07 01:50:51 +00:00
|
|
|
Ui: ui,
|
|
|
|
},
|
2013-12-31 21:06:33 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2017-02-08 21:56:58 +00:00
|
|
|
"info": func() (cli.Command, error) {
|
|
|
|
return &command.InfoCommand{
|
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2017-02-08 22:14:02 +00:00
|
|
|
"join": func() (cli.Command, error) {
|
|
|
|
return &command.JoinCommand{
|
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2017-02-08 22:19:17 +00:00
|
|
|
"keygen": func() (cli.Command, error) {
|
|
|
|
return &command.KeygenCommand{
|
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetNone,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2017-02-08 23:25:47 +00:00
|
|
|
"keyring": func() (cli.Command, error) {
|
|
|
|
return &command.KeyringCommand{
|
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-09-26 15:10:58 +00:00
|
|
|
"kv": func() (cli.Command, error) {
|
|
|
|
return &command.KVCommand{
|
2017-02-09 00:26:24 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetNone,
|
|
|
|
},
|
2016-09-26 15:10:58 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-09-26 15:12:40 +00:00
|
|
|
"kv delete": func() (cli.Command, error) {
|
|
|
|
return &command.KVDeleteCommand{
|
2017-02-09 00:26:24 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
},
|
2016-09-26 15:12:40 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-09-26 15:12:14 +00:00
|
|
|
"kv get": func() (cli.Command, error) {
|
|
|
|
return &command.KVGetCommand{
|
2017-02-09 00:26:24 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
},
|
2016-09-26 15:12:14 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-09-26 15:12:29 +00:00
|
|
|
"kv put": func() (cli.Command, error) {
|
|
|
|
return &command.KVPutCommand{
|
2017-02-09 00:26:24 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
},
|
2016-09-26 15:12:29 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2017-01-05 00:24:09 +00:00
|
|
|
"kv export": func() (cli.Command, error) {
|
|
|
|
return &command.KVExportCommand{
|
2017-02-09 00:26:24 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
},
|
2017-01-05 00:24:09 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"kv import": func() (cli.Command, error) {
|
|
|
|
return &command.KVImportCommand{
|
2017-02-09 00:26:24 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Ui: ui,
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
},
|
2014-09-06 18:12:45 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-31 21:06:33 +00:00
|
|
|
"leave": func() (cli.Command, error) {
|
|
|
|
return &command.LeaveCommand{
|
2017-02-09 21:41:17 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2013-12-31 21:06:33 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2015-01-20 00:37:58 +00:00
|
|
|
"lock": func() (cli.Command, error) {
|
|
|
|
return &command.LockCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
2017-02-08 00:16:33 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
2016-10-09 04:10:40 +00:00
|
|
|
Ui: ui,
|
|
|
|
},
|
2015-01-20 00:37:58 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2015-01-21 21:00:14 +00:00
|
|
|
"maint": func() (cli.Command, error) {
|
|
|
|
return &command.MaintCommand{
|
2017-02-09 21:50:45 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2015-01-21 21:00:14 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-31 21:06:33 +00:00
|
|
|
"members": func() (cli.Command, error) {
|
|
|
|
return &command.MembersCommand{
|
2017-02-09 22:12:47 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2013-12-31 21:06:33 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"monitor": func() (cli.Command, error) {
|
|
|
|
return &command.MonitorCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
2017-02-09 22:31:52 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2013-12-31 21:06:33 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-08-30 02:09:57 +00:00
|
|
|
"operator": func() (cli.Command, error) {
|
|
|
|
return &command.OperatorCommand{
|
2017-02-15 21:30:07 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetNone,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"operator raft": func() (cli.Command, error) {
|
|
|
|
return &command.OperatorRaftCommand{
|
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"operator raft list-peers": func() (cli.Command, error) {
|
|
|
|
return &command.OperatorRaftListCommand{
|
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"operator raft remove-peer": func() (cli.Command, error) {
|
|
|
|
return &command.OperatorRaftRemoveCommand{
|
2017-02-09 23:19:34 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2016-08-30 02:09:57 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2014-06-11 17:58:26 +00:00
|
|
|
"reload": func() (cli.Command, error) {
|
|
|
|
return &command.ReloadCommand{
|
2017-02-10 00:32:22 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2014-06-11 17:58:26 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2015-10-16 07:03:16 +00:00
|
|
|
"rtt": func() (cli.Command, error) {
|
2015-10-22 00:21:08 +00:00
|
|
|
return &command.RTTCommand{
|
2017-02-10 00:38:06 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetClientHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2015-10-16 07:03:16 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-10-26 02:20:24 +00:00
|
|
|
"snapshot": func() (cli.Command, error) {
|
|
|
|
return &command.SnapshotCommand{
|
|
|
|
Ui: ui,
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"snapshot restore": func() (cli.Command, error) {
|
|
|
|
return &command.SnapshotRestoreCommand{
|
2017-02-10 01:00:38 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2016-10-26 02:20:24 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
|
|
|
"snapshot save": func() (cli.Command, error) {
|
|
|
|
return &command.SnapshotSaveCommand{
|
2017-02-10 01:00:38 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2016-10-26 02:20:24 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2016-10-31 23:37:27 +00:00
|
|
|
"snapshot inspect": func() (cli.Command, error) {
|
|
|
|
return &command.SnapshotInspectCommand{
|
2017-02-10 01:00:38 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetNone,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2016-10-31 23:37:27 +00:00
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2017-02-11 00:21:51 +00:00
|
|
|
"validate": func() (cli.Command, error) {
|
|
|
|
return &command.ValidateCommand{
|
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetNone,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
|
2013-12-19 19:22:08 +00:00
|
|
|
"version": func() (cli.Command, error) {
|
|
|
|
return &command.VersionCommand{
|
2016-11-03 00:27:49 +00:00
|
|
|
HumanVersion: version.GetHumanVersion(),
|
2016-07-20 01:38:15 +00:00
|
|
|
Ui: ui,
|
2013-12-19 19:22:08 +00:00
|
|
|
}, nil
|
|
|
|
},
|
2014-08-21 23:02:41 +00:00
|
|
|
|
|
|
|
"watch": func() (cli.Command, error) {
|
|
|
|
return &command.WatchCommand{
|
|
|
|
ShutdownCh: makeShutdownCh(),
|
2017-02-10 01:36:01 +00:00
|
|
|
Command: base.Command{
|
|
|
|
Flags: base.FlagSetHTTP,
|
|
|
|
Ui: ui,
|
|
|
|
},
|
2014-08-21 23:02:41 +00:00
|
|
|
}, nil
|
|
|
|
},
|
2013-12-19 19:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// makeShutdownCh returns a channel that can be used for shutdown
|
|
|
|
// notifications for commands. This channel will send a message for every
|
2015-03-30 21:50:45 +00:00
|
|
|
// interrupt or SIGTERM received.
|
2013-12-19 19:22:08 +00:00
|
|
|
func makeShutdownCh() <-chan struct{} {
|
|
|
|
resultCh := make(chan struct{})
|
|
|
|
|
|
|
|
signalCh := make(chan os.Signal, 4)
|
2015-03-30 21:50:45 +00:00
|
|
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
|
2013-12-19 19:22:08 +00:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
<-signalCh
|
|
|
|
resultCh <- struct{}{}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return resultCh
|
|
|
|
}
|