2017-09-25 18:40:42 +00:00
package config
import (
"flag"
"fmt"
"time"
)
// Flags defines the command line flags.
type Flags struct {
// Config contains the command line arguments that can also be set
// in a config file.
Config Config
// ConfigFiles contains the list of config files and directories
// that should be read.
ConfigFiles [ ] string
2017-10-31 22:30:01 +00:00
// ConfigFormat forces all config files to be interpreted as this
// format independent of their extension.
ConfigFormat * string
2017-09-25 18:40:42 +00:00
// DevMode indicates whether the agent should be started in development
// mode. This cannot be configured in a config file.
DevMode * bool
2020-05-01 22:17:28 +00:00
// HCL contains an arbitrary config in hcl format.
2017-09-25 18:40:42 +00:00
HCL [ ] string
}
// AddFlags adds the command line flags for the agent.
func AddFlags ( fs * flag . FlagSet , f * Flags ) {
add := func ( p interface { } , name , help string ) {
switch x := p . ( type ) {
case * * bool :
fs . Var ( newBoolPtrValue ( x ) , name , help )
case * * time . Duration :
fs . Var ( newDurationPtrValue ( x ) , name , help )
case * * int :
fs . Var ( newIntPtrValue ( x ) , name , help )
case * * string :
fs . Var ( newStringPtrValue ( x ) , name , help )
case * [ ] string :
fs . Var ( newStringSliceValue ( x ) , name , help )
case * map [ string ] string :
fs . Var ( newStringMapValue ( x ) , name , help )
default :
panic ( fmt . Sprintf ( "invalid type: %T" , p ) )
}
}
// command line flags ordered by flag name
add ( & f . Config . AdvertiseAddrLAN , "advertise" , "Sets the advertise address to use." )
add ( & f . Config . AdvertiseAddrWAN , "advertise-wan" , "Sets address to advertise on WAN instead of -advertise address." )
add ( & f . Config . BindAddr , "bind" , "Sets the bind address for cluster communication." )
2018-07-06 18:05:06 +00:00
add ( & f . Config . Ports . Server , "server-port" , "Sets the server port to listen on." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . Bootstrap , "bootstrap" , "Sets server to bootstrap mode." )
add ( & f . Config . BootstrapExpect , "bootstrap-expect" , "Sets server to expect bootstrap mode." )
2018-10-03 13:05:28 +00:00
add ( & f . Config . ClientAddr , "client" , "Sets the address to bind for client access. This includes RPC, DNS, HTTP, HTTPS and gRPC (if configured)." )
2019-06-26 15:43:25 +00:00
add ( & f . Config . CheckOutputMaxSize , "check_output_max_size" , "Sets the maximum output size for checks on this agent" )
2017-09-25 18:40:42 +00:00
add ( & f . ConfigFiles , "config-dir" , "Path to a directory to read configuration files from. This will read every file ending in '.json' as configuration in this directory in alphabetical order. Can be specified multiple times." )
2019-04-30 18:43:32 +00:00
add ( & f . ConfigFiles , "config-file" , "Path to a file in JSON or HCL format with a matching file extension. Can be specified multiple times." )
2017-10-31 22:30:01 +00:00
add ( & f . ConfigFormat , "config-format" , "Config files are in this format irrespective of their extension. Must be 'hcl' or 'json'" )
2017-09-25 18:40:42 +00:00
add ( & f . Config . DataDir , "data-dir" , "Path to a data directory to store agent state." )
add ( & f . Config . Datacenter , "datacenter" , "Datacenter of the agent." )
2020-01-17 13:20:57 +00:00
add ( & f . Config . DefaultQueryTime , "default-query-time" , "the amount of time a blocking query will wait before Consul will force a response. This value can be overridden by the 'wait' query parameter." )
2017-09-25 18:40:42 +00:00
add ( & f . DevMode , "dev" , "Starts the agent in development mode." )
add ( & f . Config . DisableHostNodeID , "disable-host-node-id" , "Setting this to true will prevent Consul from using information from the host to generate a node ID, and will cause Consul to generate a random node ID instead." )
add ( & f . Config . DisableKeyringFile , "disable-keyring-file" , "Disables the backing up of the keyring to a file." )
add ( & f . Config . Ports . DNS , "dns-port" , "DNS port to use." )
add ( & f . Config . DNSDomain , "domain" , "Domain to use for DNS interface." )
2019-06-27 10:00:37 +00:00
add ( & f . Config . DNSAltDomain , "alt-domain" , "Alternate domain to use for DNS interface." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . EnableScriptChecks , "enable-script-checks" , "Enables health check scripts." )
2018-10-11 12:22:11 +00:00
add ( & f . Config . EnableLocalScriptChecks , "enable-local-script-checks" , "Enables health check scripts from configuration file." )
2019-01-10 14:27:26 +00:00
add ( & f . Config . HTTPConfig . AllowWriteHTTPFrom , "allow-write-http-from" , "Only allow write endpoint calls from given network. CIDR format, can be specified multiple times." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . EncryptKey , "encrypt" , "Provides the gossip encryption key." )
2018-10-03 13:05:28 +00:00
add ( & f . Config . Ports . GRPC , "grpc-port" , "Sets the gRPC API port to listen on (currently needed for Envoy xDS only)." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . Ports . HTTP , "http-port" , "Sets the HTTP API port to listen on." )
2020-01-22 10:32:17 +00:00
add ( & f . Config . Ports . HTTPS , "https-port" , "Sets the HTTPS API port to listen on." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . StartJoinAddrsLAN , "join" , "Address of an agent to join at start time. Can be specified multiple times." )
add ( & f . Config . StartJoinAddrsWAN , "join-wan" , "Address of an agent to join -wan at start time. Can be specified multiple times." )
add ( & f . Config . LogLevel , "log-level" , "Log level of the agent." )
2020-01-28 23:50:41 +00:00
add ( & f . Config . LogJSON , "log-json" , "Output logs in JSON format." )
2018-08-29 20:56:58 +00:00
add ( & f . Config . LogFile , "log-file" , "Path to the file the logs get written to" )
add ( & f . Config . LogRotateBytes , "log-rotate-bytes" , "Maximum number of bytes that should be written to a log file" )
add ( & f . Config . LogRotateDuration , "log-rotate-duration" , "Time after which log rotation needs to be performed" )
2019-07-19 21:36:34 +00:00
add ( & f . Config . LogRotateMaxFiles , "log-rotate-max-files" , "Maximum number of log file archives to keep" )
2020-01-17 13:20:57 +00:00
add ( & f . Config . MaxQueryTime , "max-query-time" , "the maximum amount of time a blocking query can wait before Consul will force a response. Consul applies jitter to the wait time. The jittered time will be capped to MaxQueryTime." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . NodeName , "node" , "Name of this node. Must be unique in the cluster." )
add ( & f . Config . NodeID , "node-id" , "A unique ID for this node across space and time. Defaults to a randomly-generated ID that persists in the data-dir." )
add ( & f . Config . NodeMeta , "node-meta" , "An arbitrary metadata key/value pair for this node, of the format `key:value`. Can be specified multiple times." )
add ( & f . Config . NonVotingServer , "non-voting-server" , "(Enterprise-only) This flag is used to make the server not participate in the Raft quorum, and have it only receive the data replication stream. This can be used to add read scalability to a cluster in cases where a high volume of reads to servers are needed." )
add ( & f . Config . PidFile , "pid-file" , "Path to file to store agent PID." )
add ( & f . Config . RPCProtocol , "protocol" , "Sets the protocol version. Defaults to latest." )
add ( & f . Config . RaftProtocol , "raft-protocol" , "Sets the Raft protocol version. Defaults to latest." )
add ( & f . Config . DNSRecursors , "recursor" , "Address of an upstream DNS server. Can be specified multiple times." )
2020-03-09 20:59:02 +00:00
add ( & f . Config . PrimaryGateways , "primary-gateway" , "Address of a mesh gateway in the primary datacenter to use to bootstrap WAN federation at start time with retries enabled. Can be specified multiple times." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . RejoinAfterLeave , "rejoin" , "Ignores a previous leave and attempts to rejoin the cluster." )
add ( & f . Config . RetryJoinIntervalLAN , "retry-interval" , "Time to wait between join attempts." )
add ( & f . Config . RetryJoinIntervalWAN , "retry-interval-wan" , "Time to wait between join -wan attempts." )
add ( & f . Config . RetryJoinLAN , "retry-join" , "Address of an agent to join at start time with retries enabled. Can be specified multiple times." )
add ( & f . Config . RetryJoinWAN , "retry-join-wan" , "Address of an agent to join -wan at start time with retries enabled. Can be specified multiple times." )
add ( & f . Config . RetryJoinMaxAttemptsLAN , "retry-max" , "Maximum number of join attempts. Defaults to 0, which will retry indefinitely." )
add ( & f . Config . RetryJoinMaxAttemptsWAN , "retry-max-wan" , "Maximum number of join -wan attempts. Defaults to 0, which will retry indefinitely." )
2020-05-20 09:31:19 +00:00
add ( & f . Config . SerfAllowedCIDRsLAN , "serf-lan-allowed-cidrs" , "Networks (eg: 192.168.1.0/24) allowed for Serf LAN. Can be specified multiple times." )
add ( & f . Config . SerfAllowedCIDRsWAN , "serf-wan-allowed-cidrs" , "Networks (eg: 192.168.1.0/24) allowed for Serf WAN (other datacenters). Can be specified multiple times." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . SerfBindAddrLAN , "serf-lan-bind" , "Address to bind Serf LAN listeners to." )
2018-07-06 18:05:06 +00:00
add ( & f . Config . Ports . SerfLAN , "serf-lan-port" , "Sets the Serf LAN port to listen on." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . SegmentName , "segment" , "(Enterprise-only) Sets the network segment to join." )
add ( & f . Config . SerfBindAddrWAN , "serf-wan-bind" , "Address to bind Serf WAN listeners to." )
2018-07-06 18:05:06 +00:00
add ( & f . Config . Ports . SerfWAN , "serf-wan-port" , "Sets the Serf WAN port to listen on." )
2017-09-25 18:40:42 +00:00
add ( & f . Config . ServerMode , "server" , "Switches agent to server mode." )
add ( & f . Config . EnableSyslog , "syslog" , "Enables logging to syslog." )
2017-09-26 06:58:54 +00:00
add ( & f . Config . UI , "ui" , "Enables the built-in static web UI server." )
ui: modify content path (#5950)
* Add ui-content-path flag
* tests complete, regex validator on string, index.html updated
* cleaning up debugging stuff
* ui: Enable ember environment configuration to be set via the go binary at runtime (#5934)
* ui: Only inject {{.ContentPath}} if we are makeing a prod build...
...otherwise we just use the current rootURL
This gets injected into a <base /> node which solves the assets path
problem but not the ember problem
* ui: Pull out the <base href=""> value and inject it into ember env
See previous commit:
The <base href=""> value is 'sometimes' injected from go at index
serve time. We pass this value down to ember by overwriting the ember
config that is injected via a <meta> tag. This has to be done before
ember bootup.
Sometimes (during testing and development, basically not production)
this is injected with the already existing value, in which case this
essentially changes nothing.
The code here is slightly abstracted away from our specific usage to
make it easier for anyone else to use, and also make sure we can cope
with using this same method to pass variables down from the CLI through
to ember in the future.
* ui: We can't use <base /> move everything to javascript (#5941)
Unfortuantely we can't seem to be able to use <base> and rootURL
together as URL paths will get doubled up (`ui/ui/`).
This moves all the things that we need to interpolate with .ContentPath
to the `startup` javascript so we can conditionally print out
`{{.ContentPath}}` in lots of places (now we can't use base)
* fixed when we serve index.html
* ui: For writing a ContentPath, we also need to cope with testing... (#5945)
...and potentially more environments
Testing has more additional things in a separate index.html in `tests/`
This make the entire thing a little saner and uses just javascriopt
template literals instead of a pseudo handbrake synatx for our
templating of these files.
Intead of just templating the entire file this way, we still only
template `{{content-for 'head'}}` and `{{content-for 'body'}}`
in this way to ensure we support other plugins/addons
* build: Loosen up the regex for retrieving the CONSUL_VERSION (#5946)
* build: Loosen up the regex for retrieving the CONSUL_VERSION
1. Previously the `sed` replacement was searching for the CONSUL_VERSION
comment at the start of a line, it no longer does this to allow for
indentation.
2. Both `grep` and `sed` where looking for the omment at the end of the
line. We've removed this restriction here. We don't need to remove it
right now, but if we ever put the comment followed by something here the
searching would break.
3. Added `xargs` for trimming the resulting version string. We aren't
using this already in the rest of the scripts, but we are pretty sure
this is available on most systems.
* ui: Fix erroneous variable, and also force an ember cache clean on build
1. We referenced a variable incorrectly here, this fixes that.
2. We also made sure that every `make` target clears ember's `tmp` cache
to ensure that its not using any caches that have since been edited
everytime we call a `make` target.
* added docs, fixed encoding
* fixed go fmt
* Update agent/config/config.go
Co-Authored-By: R.B. Boyer <public@richardboyer.net>
* Completed Suggestions
* run gofmt on http.go
* fix testsanitize
* fix fullconfig/hcl by setting correct 'want'
* ran gofmt on agent/config/runtime_test.go
* Update website/source/docs/agent/options.html.md
Co-Authored-By: Hans Hasselberg <me@hans.io>
* Update website/source/docs/agent/options.html.md
Co-Authored-By: kaitlincarter-hc <43049322+kaitlincarter-hc@users.noreply.github.com>
* remove contentpath from redirectFS struct
2019-06-26 16:43:30 +00:00
add ( & f . Config . UIContentPath , "ui-content-path" , "Sets the external UI path to a string. Defaults to: /ui/ " )
2017-09-25 18:40:42 +00:00
add ( & f . Config . UIDir , "ui-dir" , "Path to directory containing the web UI resources." )
add ( & f . HCL , "hcl" , "hcl config fragment. Can be specified multiple times." )
}