From 7b5da2a2408de54f35335c5055709b2c64bcd7e2 Mon Sep 17 00:00:00 2001 From: Andy Lo-A-Foe Date: Tue, 11 Aug 2015 14:14:21 +0200 Subject: [PATCH] Add -http-port option to change the HTTP API port This is useful when pushing consul to PaaS like Cloud Foundry making the HTTP API easily routable. --- command/agent/command.go | 1 + command/agent/config.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/command/agent/command.go b/command/agent/command.go index 008eed42d8..e3ce2787e2 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -80,6 +80,7 @@ func (c *Command) readConfig() *Config { cmdFlags.StringVar(&cmdConfig.ClientAddr, "client", "", "address to bind client listeners to (DNS, HTTP, HTTPS, RPC)") cmdFlags.StringVar(&cmdConfig.BindAddr, "bind", "", "address to bind server listeners to") + cmdFlags.IntVar(&cmdConfig.HttpPort, "http-port", 0, "http port to use") cmdFlags.StringVar(&cmdConfig.AdvertiseAddr, "advertise", "", "address to advertise instead of bind addr") cmdFlags.StringVar(&cmdConfig.AdvertiseAddrWan, "advertise-wan", "", "address to advertise on wan instead of bind or advertise addr") diff --git a/command/agent/config.go b/command/agent/config.go index 5b3357a34e..22331d0d63 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -141,6 +141,11 @@ type Config struct { // client services (DNS, HTTP, HTTPS, RPC) ClientAddr string `mapstructure:"client_addr"` + // HttpPort the HTTP port to listen on. + // This is useful e.g. when deploying to Cloud Foundry to make + // the HTTP API easily routable + HttpPort int `mapstructure:"http_port"` + // BindAddr is used to control the address we bind to. // If not specified, the first private IP we find is used. // This controls the address we use for cluster facing @@ -849,6 +854,9 @@ func MergeConfig(a, b *Config) *Config { if b.BindAddr != "" { result.BindAddr = b.BindAddr } + if b.HttpPort != 0 { + result.Ports.HTTP = b.HttpPort + } if b.AdvertiseAddr != "" { result.AdvertiseAddr = b.AdvertiseAddr }