agent: only ignore errors on IsNotExist()

This commit is contained in:
Ryan Uber 2015-01-16 09:14:52 -08:00
parent ad19c0afc2
commit 61d2f71d14
3 changed files with 17 additions and 22 deletions

View File

@ -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
}
}

View File

@ -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
}
}

View File

@ -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`