From 61d2f71d14d8c18ab3cafc1a57b31dfba41ee133 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Fri, 16 Jan 2015 09:14:52 -0800 Subject: [PATCH] agent: only ignore errors on IsNotExist() --- command/agent/command.go | 6 ++---- command/agent/http.go | 12 ++++------- .../source/docs/agent/options.html.markdown | 21 ++++++++++--------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index a677b03b9..3afafca5e 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -299,10 +299,8 @@ func (c *Command) setupAgent(config *Config, logOutput io.Writer, logWriter *log // Remove the socket if it exists, or we'll get a bind error. This // is necessary to avoid situations where Consul cannot start if the // socket file exists in case of unexpected termination. - if _, err := os.Stat(path); err == nil { - if err := os.Remove(path); err != nil { - return err - } + if err := os.Remove(path); err != nil && !os.IsNotExist(err) { + return err } } diff --git a/command/agent/http.go b/command/agent/http.go index 2d26e60b1..19a3dc0bf 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -61,10 +61,8 @@ func NewHTTPServers(agent *Agent, config *Config, logOutput io.Writer) ([]*HTTPS if path, ok := unixSocketAddr(config.Addresses.HTTPS); ok { // See command/agent/config.go - if _, err := os.Stat(path); err == nil { - if err := os.Remove(path); err != nil { - return nil, err - } + if err := os.Remove(path); err != nil && !os.IsNotExist(err) { + return nil, err } } @@ -106,10 +104,8 @@ func NewHTTPServers(agent *Agent, config *Config, logOutput io.Writer) ([]*HTTPS if path, ok := unixSocketAddr(config.Addresses.HTTP); ok { // See command/agent/config.go - if _, err := os.Stat(path); err == nil { - if err := os.Remove(path); err != nil { - return nil, err - } + if err := os.Remove(path); err != nil && !os.IsNotExist(err) { + return nil, err } } diff --git a/website/source/docs/agent/options.html.markdown b/website/source/docs/agent/options.html.markdown index 6aa6b61d8..b7423dabe 100644 --- a/website/source/docs/agent/options.html.markdown +++ b/website/source/docs/agent/options.html.markdown @@ -240,16 +240,17 @@ definitions support being updated during a reload. up to the TTL value. * `addresses` - This is a nested object that allows setting bind addresses. For `rpc` - and `http`, a Unix socket can be specified in the following form: - unix://[/path/to/socket];[username|uid];[gid];[mode]. The socket will be created - in the specified location with the given username or uid, gid, and mode. The - user Consul is running as must have appropriate permissions to change the socket - ownership to the given uid or gid. When running Consul agent commands against - Unix socket interfaces, use the `-rpc-addr` or `-http-addr` arguments to specify - the path to the socket, e.g. "unix://path/to/socket". You can also place the desired - values in `CONSUL_RPC_ADDR` and `CONSUL_HTTP_ADDR` environment variables. For TCP - addresses, these should be in the form ip:port. - The following keys are valid: + and `http`, a Unix socket can be specified in the following form + `unix:///path/to/socket`. A new domain socket will be created at the given + path. Any existing socket file (or any other kind of file) at the specified + path will be **overwritten**, so use caution when configuring this argument. + + When running Consul agent commands against Unix socket interfaces, use the + `-rpc-addr` or `-http-addr` arguments to specify the path to the socket. You + can also place the desired values in `CONSUL_RPC_ADDR` and `CONSUL_HTTP_ADDR` + environment variables. For TCP addresses, these should be in the form ip:port. + + The following keys are valid: * `dns` - The DNS server. Defaults to `client_addr` * `http` - The HTTP API. Defaults to `client_addr` * `rpc` - The RPC endpoint. Defaults to `client_addr`