config.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. // Copyright 2015 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Every change should be reflected on help.go as well.
  15. package etcdmain
  16. import (
  17. "flag"
  18. "fmt"
  19. "io/ioutil"
  20. "net"
  21. "net/url"
  22. "os"
  23. "runtime"
  24. "strings"
  25. "github.com/coreos/etcd/etcdserver"
  26. "github.com/coreos/etcd/pkg/cors"
  27. "github.com/coreos/etcd/pkg/flags"
  28. "github.com/coreos/etcd/pkg/transport"
  29. "github.com/coreos/etcd/pkg/types"
  30. "github.com/coreos/etcd/version"
  31. "github.com/ghodss/yaml"
  32. )
  33. const (
  34. proxyFlagOff = "off"
  35. proxyFlagReadonly = "readonly"
  36. proxyFlagOn = "on"
  37. fallbackFlagExit = "exit"
  38. fallbackFlagProxy = "proxy"
  39. clusterStateFlagNew = "new"
  40. clusterStateFlagExisting = "existing"
  41. defaultName = "default"
  42. defaultInitialAdvertisePeerURLs = "http://localhost:2380"
  43. defaultAdvertiseClientURLs = "http://localhost:2379"
  44. defaultListenPeerURLs = "http://localhost:2380"
  45. defaultListenClientURLs = "http://localhost:2379"
  46. // maxElectionMs specifies the maximum value of election timeout.
  47. // More details are listed in ../Documentation/tuning.md#time-parameters.
  48. maxElectionMs = 50000
  49. )
  50. var (
  51. ignored = []string{
  52. "cluster-active-size",
  53. "cluster-remove-delay",
  54. "cluster-sync-interval",
  55. "config",
  56. "force",
  57. "max-result-buffer",
  58. "max-retry-attempts",
  59. "peer-heartbeat-interval",
  60. "peer-election-timeout",
  61. "retry-interval",
  62. "snapshot",
  63. "v",
  64. "vv",
  65. }
  66. ErrConflictBootstrapFlags = fmt.Errorf("multiple discovery or bootstrap flags are set. " +
  67. "Choose one of \"initial-cluster\", \"discovery\" or \"discovery-srv\"")
  68. errUnsetAdvertiseClientURLsFlag = fmt.Errorf("--advertise-client-urls is required when --listen-client-urls is set explicitly")
  69. )
  70. type config struct {
  71. *flag.FlagSet
  72. // member
  73. corsInfo *cors.CORSInfo
  74. lpurls, lcurls []url.URL
  75. Dir string `json:"data-dir"`
  76. WalDir string `json:"wal-dir"`
  77. MaxSnapFiles uint `json:"max-snapshots"`
  78. MaxWalFiles uint `json:"max-wals"`
  79. Name string `json:"name"`
  80. SnapCount uint64 `json:"snapshot-count"`
  81. LPUrlsCfgFile string `json:"listen-peer-urls"`
  82. LCUrlsCfgFile string `json:"listen-client-urls"`
  83. CorsCfgFile string `json:"cors"`
  84. // TickMs is the number of milliseconds between heartbeat ticks.
  85. // TODO: decouple tickMs and heartbeat tick (current heartbeat tick = 1).
  86. // make ticks a cluster wide configuration.
  87. TickMs uint `json:"heartbeat-interval"`
  88. ElectionMs uint `json:"election-timeout"`
  89. QuotaBackendBytes int64 `json:"quota-backend-bytes"`
  90. // clustering
  91. apurls, acurls []url.URL
  92. clusterState *flags.StringsFlag
  93. DnsCluster string `json:"discovery-srv"`
  94. Dproxy string `json:"discovery-proxy"`
  95. Durl string `json:"discovery"`
  96. fallback *flags.StringsFlag
  97. InitialCluster string `json:"initial-cluster"`
  98. InitialClusterToken string `json:"initial-cluster-token"`
  99. StrictReconfigCheck bool `json:"strict-reconfig-check"`
  100. ApurlsCfgFile string `json:"initial-advertise-peer-urls"`
  101. AcurlsCfgFile string `json:"advertise-client-urls"`
  102. ClusterStateCfgFile string `json:"initial-cluster-state"`
  103. FallbackCfgFile string `json:"discovery-fallback"`
  104. // proxy
  105. proxy *flags.StringsFlag
  106. ProxyFailureWaitMs uint `json:"proxy-failure-wait"`
  107. ProxyRefreshIntervalMs uint `json:"proxy-refresh-interval"`
  108. ProxyDialTimeoutMs uint `json:"proxy-dial-timeout"`
  109. ProxyWriteTimeoutMs uint `json:"proxy-write-timeout"`
  110. ProxyReadTimeoutMs uint `json:"proxy-read-timeout"`
  111. ProxyCfgFile string `json:"proxy"`
  112. // security
  113. clientTLSInfo, peerTLSInfo transport.TLSInfo
  114. ClientAutoTLS bool
  115. PeerAutoTLS bool
  116. ClientSecurityCfgFile securityConfig `json:"client-transport-security"`
  117. PeerSecurityCfgFile securityConfig `json:"peer-transport-security"`
  118. // Debug logging
  119. Debug bool `json:"debug"`
  120. LogPkgLevels string `json:"log-package-levels"`
  121. // ForceNewCluster is unsafe
  122. ForceNewCluster bool `json:"force-new-cluster"`
  123. printVersion bool
  124. autoCompactionRetention int
  125. enablePprof bool
  126. configFile string
  127. ignored []string
  128. }
  129. type securityConfig struct {
  130. CAFile string `json:"ca-file"`
  131. CertFile string `json:"cert-file"`
  132. KeyFile string `json:"key-file"`
  133. CertAuth bool `json:"client-cert-auth"`
  134. TrustedCAFile string `json:"trusted-ca-file"`
  135. AutoTLS bool `json:"auto-tls"`
  136. }
  137. func NewConfig() *config {
  138. cfg := &config{
  139. corsInfo: &cors.CORSInfo{},
  140. clusterState: flags.NewStringsFlag(
  141. clusterStateFlagNew,
  142. clusterStateFlagExisting,
  143. ),
  144. fallback: flags.NewStringsFlag(
  145. fallbackFlagExit,
  146. fallbackFlagProxy,
  147. ),
  148. ignored: ignored,
  149. proxy: flags.NewStringsFlag(
  150. proxyFlagOff,
  151. proxyFlagReadonly,
  152. proxyFlagOn,
  153. ),
  154. }
  155. cfg.FlagSet = flag.NewFlagSet("etcd", flag.ContinueOnError)
  156. fs := cfg.FlagSet
  157. fs.Usage = func() {
  158. fmt.Println(usageline)
  159. }
  160. fs.StringVar(&cfg.configFile, "config-file", "", "Path to the server configuration file")
  161. // member
  162. fs.Var(cfg.corsInfo, "cors", "Comma-separated white list of origins for CORS (cross-origin resource sharing).")
  163. fs.StringVar(&cfg.Dir, "data-dir", "", "Path to the data directory.")
  164. fs.StringVar(&cfg.WalDir, "wal-dir", "", "Path to the dedicated wal directory.")
  165. fs.Var(flags.NewURLsValue(defaultListenPeerURLs), "listen-peer-urls", "List of URLs to listen on for peer traffic.")
  166. fs.Var(flags.NewURLsValue(defaultListenClientURLs), "listen-client-urls", "List of URLs to listen on for client traffic.")
  167. fs.UintVar(&cfg.MaxSnapFiles, "max-snapshots", defaultMaxSnapshots, "Maximum number of snapshot files to retain (0 is unlimited).")
  168. fs.UintVar(&cfg.MaxWalFiles, "max-wals", defaultMaxWALs, "Maximum number of wal files to retain (0 is unlimited).")
  169. fs.StringVar(&cfg.Name, "name", defaultName, "Human-readable name for this member.")
  170. fs.Uint64Var(&cfg.SnapCount, "snapshot-count", etcdserver.DefaultSnapCount, "Number of committed transactions to trigger a snapshot to disk.")
  171. fs.UintVar(&cfg.TickMs, "heartbeat-interval", 100, "Time (in milliseconds) of a heartbeat interval.")
  172. fs.UintVar(&cfg.ElectionMs, "election-timeout", 1000, "Time (in milliseconds) for an election to timeout.")
  173. fs.Int64Var(&cfg.QuotaBackendBytes, "quota-backend-bytes", 0, "Raise alarms when backend size exceeds the given quota. 0 means use the default quota.")
  174. // clustering
  175. fs.Var(flags.NewURLsValue(defaultInitialAdvertisePeerURLs), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster.")
  176. fs.Var(flags.NewURLsValue(defaultAdvertiseClientURLs), "advertise-client-urls", "List of this member's client URLs to advertise to the public.")
  177. fs.StringVar(&cfg.Durl, "discovery", "", "Discovery URL used to bootstrap the cluster.")
  178. fs.Var(cfg.fallback, "discovery-fallback", fmt.Sprintf("Valid values include %s", strings.Join(cfg.fallback.Values, ", ")))
  179. if err := cfg.fallback.Set(fallbackFlagProxy); err != nil {
  180. // Should never happen.
  181. plog.Panicf("unexpected error setting up discovery-fallback flag: %v", err)
  182. }
  183. fs.StringVar(&cfg.Dproxy, "discovery-proxy", "", "HTTP proxy to use for traffic to discovery service.")
  184. fs.StringVar(&cfg.DnsCluster, "discovery-srv", "", "DNS domain used to bootstrap initial cluster.")
  185. fs.StringVar(&cfg.InitialCluster, "initial-cluster", initialClusterFromName(defaultName), "Initial cluster configuration for bootstrapping.")
  186. fs.StringVar(&cfg.InitialClusterToken, "initial-cluster-token", "etcd-cluster", "Initial cluster token for the etcd cluster during bootstrap.")
  187. fs.Var(cfg.clusterState, "initial-cluster-state", "Initial cluster state ('new' or 'existing').")
  188. if err := cfg.clusterState.Set(clusterStateFlagNew); err != nil {
  189. // Should never happen.
  190. plog.Panicf("unexpected error setting up clusterStateFlag: %v", err)
  191. }
  192. fs.BoolVar(&cfg.StrictReconfigCheck, "strict-reconfig-check", false, "Reject reconfiguration requests that would cause quorum loss.")
  193. // proxy
  194. fs.Var(cfg.proxy, "proxy", fmt.Sprintf("Valid values include %s", strings.Join(cfg.proxy.Values, ", ")))
  195. if err := cfg.proxy.Set(proxyFlagOff); err != nil {
  196. // Should never happen.
  197. plog.Panicf("unexpected error setting up proxyFlag: %v", err)
  198. }
  199. fs.UintVar(&cfg.ProxyFailureWaitMs, "proxy-failure-wait", 5000, "Time (in milliseconds) an endpoint will be held in a failed state.")
  200. fs.UintVar(&cfg.ProxyRefreshIntervalMs, "proxy-refresh-interval", 30000, "Time (in milliseconds) of the endpoints refresh interval.")
  201. fs.UintVar(&cfg.ProxyDialTimeoutMs, "proxy-dial-timeout", 1000, "Time (in milliseconds) for a dial to timeout.")
  202. fs.UintVar(&cfg.ProxyWriteTimeoutMs, "proxy-write-timeout", 5000, "Time (in milliseconds) for a write to timeout.")
  203. fs.UintVar(&cfg.ProxyReadTimeoutMs, "proxy-read-timeout", 0, "Time (in milliseconds) for a read to timeout.")
  204. // security
  205. fs.StringVar(&cfg.clientTLSInfo.CAFile, "ca-file", "", "DEPRECATED: Path to the client server TLS CA file.")
  206. fs.StringVar(&cfg.clientTLSInfo.CertFile, "cert-file", "", "Path to the client server TLS cert file.")
  207. fs.StringVar(&cfg.clientTLSInfo.KeyFile, "key-file", "", "Path to the client server TLS key file.")
  208. fs.BoolVar(&cfg.clientTLSInfo.ClientCertAuth, "client-cert-auth", false, "Enable client cert authentication.")
  209. fs.StringVar(&cfg.clientTLSInfo.TrustedCAFile, "trusted-ca-file", "", "Path to the client server TLS trusted CA key file.")
  210. fs.BoolVar(&cfg.ClientAutoTLS, "auto-tls", false, "Client TLS using generated certificates")
  211. fs.StringVar(&cfg.peerTLSInfo.CAFile, "peer-ca-file", "", "DEPRECATED: Path to the peer server TLS CA file.")
  212. fs.StringVar(&cfg.peerTLSInfo.CertFile, "peer-cert-file", "", "Path to the peer server TLS cert file.")
  213. fs.StringVar(&cfg.peerTLSInfo.KeyFile, "peer-key-file", "", "Path to the peer server TLS key file.")
  214. fs.BoolVar(&cfg.peerTLSInfo.ClientCertAuth, "peer-client-cert-auth", false, "Enable peer client cert authentication.")
  215. fs.StringVar(&cfg.peerTLSInfo.TrustedCAFile, "peer-trusted-ca-file", "", "Path to the peer server TLS trusted CA file.")
  216. fs.BoolVar(&cfg.PeerAutoTLS, "peer-auto-tls", false, "Peer TLS using generated certificates")
  217. // logging
  218. fs.BoolVar(&cfg.Debug, "debug", false, "Enable debug-level logging for etcd.")
  219. fs.StringVar(&cfg.LogPkgLevels, "log-package-levels", "", "Specify a particular log level for each etcd package (eg: 'etcdmain=CRITICAL,etcdserver=DEBUG').")
  220. // unsafe
  221. fs.BoolVar(&cfg.ForceNewCluster, "force-new-cluster", false, "Force to create a new one member cluster.")
  222. // version
  223. fs.BoolVar(&cfg.printVersion, "version", false, "Print the version and exit.")
  224. fs.IntVar(&cfg.autoCompactionRetention, "auto-compaction-retention", 0, "Auto compaction retention for mvcc key value store in hour. 0 means disable auto compaction.")
  225. // pprof profiler via HTTP
  226. fs.BoolVar(&cfg.enablePprof, "enable-pprof", false, "Enable runtime profiling data via HTTP server. Address is at client URL + \"/debug/pprof\"")
  227. // ignored
  228. for _, f := range cfg.ignored {
  229. fs.Var(&flags.IgnoredFlag{Name: f}, f, "")
  230. }
  231. return cfg
  232. }
  233. func (cfg *config) Parse(arguments []string) error {
  234. perr := cfg.FlagSet.Parse(arguments)
  235. switch perr {
  236. case nil:
  237. case flag.ErrHelp:
  238. fmt.Println(flagsline)
  239. os.Exit(0)
  240. default:
  241. os.Exit(2)
  242. }
  243. if len(cfg.FlagSet.Args()) != 0 {
  244. return fmt.Errorf("'%s' is not a valid flag", cfg.FlagSet.Arg(0))
  245. }
  246. if cfg.printVersion {
  247. fmt.Printf("etcd Version: %s\n", version.Version)
  248. fmt.Printf("Git SHA: %s\n", version.GitSHA)
  249. fmt.Printf("Go Version: %s\n", runtime.Version())
  250. fmt.Printf("Go OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
  251. os.Exit(0)
  252. }
  253. var err error
  254. if cfg.configFile != "" {
  255. plog.Infof("Loading server configuration from %q", cfg.configFile)
  256. err = cfg.configFromFile()
  257. } else {
  258. err = cfg.configFromCmdLine()
  259. }
  260. return err
  261. }
  262. func (cfg *config) configFromCmdLine() error {
  263. err := flags.SetFlagsFromEnv("ETCD", cfg.FlagSet)
  264. if err != nil {
  265. plog.Fatalf("%v", err)
  266. }
  267. cfg.lpurls = flags.URLsFromFlag(cfg.FlagSet, "listen-peer-urls")
  268. cfg.apurls = flags.URLsFromFlag(cfg.FlagSet, "initial-advertise-peer-urls")
  269. cfg.lcurls = flags.URLsFromFlag(cfg.FlagSet, "listen-client-urls")
  270. cfg.acurls = flags.URLsFromFlag(cfg.FlagSet, "advertise-client-urls")
  271. return cfg.validateConfig(func(field string) bool {
  272. return flags.IsSet(cfg.FlagSet, field)
  273. })
  274. }
  275. func (cfg *config) configFromFile() error {
  276. b, err := ioutil.ReadFile(cfg.configFile)
  277. if err != nil {
  278. return err
  279. }
  280. err = yaml.Unmarshal(b, cfg)
  281. if err != nil {
  282. return err
  283. }
  284. if cfg.LPUrlsCfgFile != "" {
  285. u, err := types.NewURLs(strings.Split(cfg.LPUrlsCfgFile, ","))
  286. if err != nil {
  287. plog.Fatalf("unexpected error setting up listen-peer-urls: %v", err)
  288. }
  289. cfg.lpurls = []url.URL(u)
  290. }
  291. if cfg.LCUrlsCfgFile != "" {
  292. u, err := types.NewURLs(strings.Split(cfg.LCUrlsCfgFile, ","))
  293. if err != nil {
  294. plog.Fatalf("unexpected error setting up listen-client-urls: %v", err)
  295. }
  296. cfg.lcurls = []url.URL(u)
  297. }
  298. if cfg.CorsCfgFile != "" {
  299. if err := cfg.corsInfo.Set(cfg.CorsCfgFile); err != nil {
  300. plog.Panicf("unexpected error setting up cors: %v", err)
  301. }
  302. }
  303. if cfg.ApurlsCfgFile != "" {
  304. u, err := types.NewURLs(strings.Split(cfg.ApurlsCfgFile, ","))
  305. if err != nil {
  306. plog.Fatalf("unexpected error setting up initial-advertise-peer-urls: %v", err)
  307. }
  308. cfg.apurls = []url.URL(u)
  309. }
  310. if cfg.AcurlsCfgFile != "" {
  311. u, err := types.NewURLs(strings.Split(cfg.AcurlsCfgFile, ","))
  312. if err != nil {
  313. plog.Fatalf("unexpected error setting up advertise-peer-urls: %v", err)
  314. }
  315. cfg.acurls = []url.URL(u)
  316. }
  317. if cfg.ClusterStateCfgFile != "" {
  318. if err := cfg.clusterState.Set(cfg.ClusterStateCfgFile); err != nil {
  319. plog.Panicf("unexpected error setting up clusterStateFlag: %v", err)
  320. }
  321. }
  322. if cfg.FallbackCfgFile != "" {
  323. if err := cfg.fallback.Set(cfg.FallbackCfgFile); err != nil {
  324. plog.Panicf("unexpected error setting up discovery-fallback flag: %v", err)
  325. }
  326. }
  327. if cfg.ProxyCfgFile != "" {
  328. if err := cfg.proxy.Set(cfg.ProxyCfgFile); err != nil {
  329. plog.Panicf("unexpected error setting up proxyFlag: %v", err)
  330. }
  331. }
  332. copySecurityDetails := func(tls *transport.TLSInfo, ysc *securityConfig) {
  333. tls.CAFile = ysc.CAFile
  334. tls.CertFile = ysc.CertFile
  335. tls.KeyFile = ysc.KeyFile
  336. tls.ClientCertAuth = ysc.CertAuth
  337. tls.TrustedCAFile = ysc.TrustedCAFile
  338. }
  339. copySecurityDetails(&cfg.clientTLSInfo, &cfg.ClientSecurityCfgFile)
  340. copySecurityDetails(&cfg.peerTLSInfo, &cfg.PeerSecurityCfgFile)
  341. cfg.ClientAutoTLS = cfg.ClientSecurityCfgFile.AutoTLS
  342. cfg.PeerAutoTLS = cfg.PeerSecurityCfgFile.AutoTLS
  343. fieldsToBeChecked := map[string]bool{
  344. "discovery": (cfg.Durl != ""),
  345. "listen-client-urls": (cfg.LCUrlsCfgFile != ""),
  346. "advertise-client-urls": (cfg.AcurlsCfgFile != ""),
  347. "initial-cluster": (cfg.InitialCluster != ""),
  348. "discovery-srv": (cfg.DnsCluster != ""),
  349. }
  350. return cfg.validateConfig(func(field string) bool {
  351. return fieldsToBeChecked[field]
  352. })
  353. }
  354. func (cfg *config) validateConfig(isSet func(field string) bool) error {
  355. if err := checkBindURLs(cfg.lpurls); err != nil {
  356. return err
  357. }
  358. if err := checkBindURLs(cfg.lcurls); err != nil {
  359. return err
  360. }
  361. // when etcd runs in member mode user needs to set --advertise-client-urls if --listen-client-urls is set.
  362. // TODO(yichengq): check this for joining through discovery service case
  363. mayFallbackToProxy := isSet("discovery") && cfg.fallback.String() == fallbackFlagProxy
  364. mayBeProxy := cfg.proxy.String() != proxyFlagOff || mayFallbackToProxy
  365. if !mayBeProxy {
  366. if isSet("listen-client-urls") && !isSet("advertise-client-urls") {
  367. return errUnsetAdvertiseClientURLsFlag
  368. }
  369. }
  370. // Check if conflicting flags are passed.
  371. nSet := 0
  372. for _, v := range []bool{isSet("discovery"), isSet("initial-cluster"), isSet("discovery-srv")} {
  373. if v {
  374. nSet += 1
  375. }
  376. }
  377. if nSet > 1 {
  378. return ErrConflictBootstrapFlags
  379. }
  380. if 5*cfg.TickMs > cfg.ElectionMs {
  381. return fmt.Errorf("--election-timeout[%vms] should be at least as 5 times as --heartbeat-interval[%vms]", cfg.ElectionMs, cfg.TickMs)
  382. }
  383. if cfg.ElectionMs > maxElectionMs {
  384. return fmt.Errorf("--election-timeout[%vms] is too long, and should be set less than %vms", cfg.ElectionMs, maxElectionMs)
  385. }
  386. return nil
  387. }
  388. func initialClusterFromName(name string) string {
  389. n := name
  390. if name == "" {
  391. n = defaultName
  392. }
  393. return fmt.Sprintf("%s=http://localhost:2380", n)
  394. }
  395. func (cfg config) isNewCluster() bool { return cfg.clusterState.String() == clusterStateFlagNew }
  396. func (cfg config) isProxy() bool { return cfg.proxy.String() != proxyFlagOff }
  397. func (cfg config) isReadonlyProxy() bool { return cfg.proxy.String() == proxyFlagReadonly }
  398. func (cfg config) shouldFallbackToProxy() bool { return cfg.fallback.String() == fallbackFlagProxy }
  399. func (cfg config) electionTicks() int { return int(cfg.ElectionMs / cfg.TickMs) }
  400. // checkBindURLs returns an error if any URL uses a domain name.
  401. // TODO: return error in 3.2.0
  402. func checkBindURLs(urls []url.URL) error {
  403. for _, url := range urls {
  404. if url.Scheme == "unix" || url.Scheme == "unixs" {
  405. continue
  406. }
  407. host, _, err := net.SplitHostPort(url.Host)
  408. if err != nil {
  409. return err
  410. }
  411. if host == "localhost" {
  412. // special case for local address
  413. // TODO: support /etc/hosts ?
  414. continue
  415. }
  416. if net.ParseIP(host) == nil {
  417. err := fmt.Errorf("expected IP in URL for binding (%s)", url.String())
  418. plog.Warning(err)
  419. }
  420. }
  421. return nil
  422. }