diff --git a/command/agent/agent.go b/command/agent/agent.go index a18fdf694..09c34450f 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -87,6 +87,9 @@ func NewAgent(config *Config, logOutput io.Writer, inmem *metrics.InmemSink) (*A if err := a.setupConsul(config.Consul); err != nil { return nil, fmt.Errorf("Failed to initialize Consul client: %v", err) } + + // TODO setup plugin loader + if err := a.setupServer(); err != nil { return nil, err } diff --git a/command/agent/command.go b/command/agent/command.go index 5eb00f709..8beadc77f 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -105,6 +105,7 @@ func (c *Command) readConfig() *Config { flags.StringVar(&cmdConfig.BindAddr, "bind", "", "") flags.StringVar(&cmdConfig.Region, "region", "", "") flags.StringVar(&cmdConfig.DataDir, "data-dir", "", "") + flags.StringVar(&cmdConfig.PluginDir, "plugin-dir", "", "") flags.StringVar(&cmdConfig.Datacenter, "dc", "", "") flags.StringVar(&cmdConfig.LogLevel, "log-level", "", "") flags.StringVar(&cmdConfig.NodeName, "node", "", "") @@ -265,6 +266,12 @@ func (c *Command) readConfig() *Config { } } + // Default the plugin directory to be under that of the data directory if it + // isn't explicitly specified. + if config.PluginDir == "" && config.DataDir != "" { + config.PluginDir = filepath.Join(config.DataDir, "plugins") + } + if dev { // Skip validation for dev mode return config @@ -289,9 +296,10 @@ func (c *Command) readConfig() *Config { // Verify the paths are absolute. dirs := map[string]string{ - "data-dir": config.DataDir, - "alloc-dir": config.Client.AllocDir, - "state-dir": config.Client.StateDir, + "data-dir": config.DataDir, + "plugin-dir": config.PluginDir, + "alloc-dir": config.Client.AllocDir, + "state-dir": config.Client.StateDir, } for k, dir := range dirs { if dir == "" { @@ -304,7 +312,7 @@ func (c *Command) readConfig() *Config { } } - // Ensure that we have the directories we neet to run. + // Ensure that we have the directories we need to run. if config.Server.Enabled && config.DataDir == "" { c.Ui.Error("Must specify data directory") return nil @@ -313,8 +321,8 @@ func (c *Command) readConfig() *Config { // The config is valid if the top-level data-dir is set or if both // alloc-dir and state-dir are set. if config.Client.Enabled && config.DataDir == "" { - if config.Client.AllocDir == "" || config.Client.StateDir == "" { - c.Ui.Error("Must specify both the state and alloc dir if data-dir is omitted.") + if config.Client.AllocDir == "" || config.Client.StateDir == "" || config.PluginDir == "" { + c.Ui.Error("Must specify the state, alloc dir, and plugin dir if data-dir is omitted.") return nil } } @@ -1012,6 +1020,10 @@ General Options (clients and servers): downloaded artifacts used by drivers. On server nodes, the data dir is also used to store the replicated log. + -plugin-dir= + The plugin directory is used to discover Nomad plugins. If not specified, + the plugin directory defaults to be that of /plugins/. + -dc= The name of the datacenter this Nomad agent is a member of. By default this is set to "dc1". diff --git a/command/agent/command_test.go b/command/agent/command_test.go index 41e51aab9..ee39d7d3f 100644 --- a/command/agent/command_test.go +++ b/command/agent/command_test.go @@ -46,7 +46,7 @@ func TestCommand_Args(t *testing.T) { }, { []string{"-client", "-alloc-dir="}, - "Must specify both the state and alloc dir if data-dir is omitted.", + "Must specify the state, alloc dir, and plugin dir if data-dir is omitted.", }, } for _, tc := range tcases { diff --git a/command/agent/config-test-fixtures/basic.hcl b/command/agent/config-test-fixtures/basic.hcl index 9dab81096..3cae860fc 100644 --- a/command/agent/config-test-fixtures/basic.hcl +++ b/command/agent/config-test-fixtures/basic.hcl @@ -2,6 +2,7 @@ region = "foobar" datacenter = "dc2" name = "my-web" data_dir = "/tmp/nomad" +plugin_dir = "/tmp/nomad-plugins" log_level = "ERR" bind_addr = "192.168.0.1" enable_debug = true diff --git a/command/agent/config.go b/command/agent/config.go index eff01b06e..2e57e00d5 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -37,6 +37,9 @@ type Config struct { // DataDir is the directory to store our state in DataDir string `mapstructure:"data_dir"` + // PluginDir is the directory to lookup plugins. + PluginDir string `mapstructure:"plugin_dir"` + // LogLevel is the level of the logs to putout LogLevel string `mapstructure:"log_level"` @@ -737,6 +740,9 @@ func (c *Config) Merge(b *Config) *Config { if b.DataDir != "" { result.DataDir = b.DataDir } + if b.PluginDir != "" { + result.PluginDir = b.PluginDir + } if b.LogLevel != "" { result.LogLevel = b.LogLevel } diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index b0f4be3a8..554aaf923 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -78,6 +78,7 @@ func parseConfig(result *Config, list *ast.ObjectList) error { "datacenter", "name", "data_dir", + "plugin_dir", "log_level", "bind_addr", "enable_debug", diff --git a/command/agent/config_parse_test.go b/command/agent/config_parse_test.go index 433789f91..1464b9e0f 100644 --- a/command/agent/config_parse_test.go +++ b/command/agent/config_parse_test.go @@ -24,6 +24,7 @@ func TestConfig_Parse(t *testing.T) { Datacenter: "dc2", NodeName: "my-web", DataDir: "/tmp/nomad", + PluginDir: "/tmp/nomad-plugins", LogLevel: "ERR", BindAddr: "192.168.0.1", EnableDebug: true, @@ -245,6 +246,7 @@ func TestConfig_Parse(t *testing.T) { Datacenter: "", NodeName: "", DataDir: "", + PluginDir: "", LogLevel: "", BindAddr: "", EnableDebug: false, diff --git a/command/agent/config_test.go b/command/agent/config_test.go index 7e567ef4b..0b6c438db 100644 --- a/command/agent/config_test.go +++ b/command/agent/config_test.go @@ -45,6 +45,7 @@ func TestConfig_Merge(t *testing.T) { Datacenter: "dc1", NodeName: "node1", DataDir: "/tmp/dir1", + PluginDir: "/tmp/pluginDir1", LogLevel: "INFO", EnableDebug: false, LeaveOnInt: false, @@ -191,6 +192,7 @@ func TestConfig_Merge(t *testing.T) { Datacenter: "dc2", NodeName: "node2", DataDir: "/tmp/dir2", + PluginDir: "/tmp/pluginDir2", LogLevel: "DEBUG", EnableDebug: true, LeaveOnInt: true,