From 8daa45c5b44c0cee53adb23a61ab5dff239d31b5 Mon Sep 17 00:00:00 2001 From: mckennajones Date: Tue, 22 Nov 2016 13:33:51 -0800 Subject: [PATCH 1/2] check if data-dir is actually a directory --- command/agent/command.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/command/agent/command.go b/command/agent/command.go index 247ffd1b90..966021014a 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -209,6 +209,12 @@ func (c *Command) readConfig() *Config { return nil } + if finfo, _ := os.Stat(config.DataDir); !finfo.IsDir() { + c.Ui.Error(fmt.Sprintf("CRITICAL: The data-dir specified at %q is not a directory", config.DataDir)) + c.Ui.Error("Consul will refuse to boot without a valid data directory") + c.Ui.Error("Please provide a valid directory and try starting again.") + } + // Ensure all endpoints are unique if err := config.verifyUniqueListeners(); err != nil { c.Ui.Error(fmt.Sprintf("All listening endpoints must be unique: %s", err)) From daa5ba87d4bef9c3c3c08c627d4d8c669614f491 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Wed, 14 Dec 2016 20:06:00 -0500 Subject: [PATCH 2/2] Handle error from stat on data-dir and shorten error message --- command/agent/command.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index 966021014a..956fe4e3f8 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -209,10 +209,12 @@ func (c *Command) readConfig() *Config { return nil } - if finfo, _ := os.Stat(config.DataDir); !finfo.IsDir() { - c.Ui.Error(fmt.Sprintf("CRITICAL: The data-dir specified at %q is not a directory", config.DataDir)) - c.Ui.Error("Consul will refuse to boot without a valid data directory") - c.Ui.Error("Please provide a valid directory and try starting again.") + if finfo, err := os.Stat(config.DataDir); err != nil { + c.Ui.Error(fmt.Sprintf("Error getting data-dir: %s", err)) + return nil + } else if !finfo.IsDir() { + c.Ui.Error(fmt.Sprintf("The data-dir specified at %q is not a directory", config.DataDir)) + return nil } // Ensure all endpoints are unique