etcd.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. // Copyright 2015 CoreOS, Inc.
  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. // TODO: support arm64
  15. // +build amd64
  16. package etcdmain
  17. import (
  18. "crypto/tls"
  19. "encoding/json"
  20. "fmt"
  21. "io/ioutil"
  22. "net"
  23. "net/http"
  24. _ "net/http/pprof"
  25. "os"
  26. "path"
  27. "reflect"
  28. "runtime"
  29. "strings"
  30. "time"
  31. "github.com/coreos/etcd/discovery"
  32. "github.com/coreos/etcd/etcdserver"
  33. "github.com/coreos/etcd/etcdserver/etcdhttp"
  34. "github.com/coreos/etcd/pkg/cors"
  35. "github.com/coreos/etcd/pkg/fileutil"
  36. pkgioutil "github.com/coreos/etcd/pkg/ioutil"
  37. "github.com/coreos/etcd/pkg/osutil"
  38. runtimeutil "github.com/coreos/etcd/pkg/runtime"
  39. "github.com/coreos/etcd/pkg/transport"
  40. "github.com/coreos/etcd/pkg/types"
  41. "github.com/coreos/etcd/proxy"
  42. "github.com/coreos/etcd/rafthttp"
  43. "github.com/coreos/etcd/version"
  44. "github.com/coreos/go-systemd/daemon"
  45. systemdutil "github.com/coreos/go-systemd/util"
  46. "github.com/coreos/pkg/capnslog"
  47. "github.com/prometheus/client_golang/prometheus"
  48. )
  49. type dirType string
  50. var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdmain")
  51. const (
  52. // the owner can make/remove files inside the directory
  53. privateDirMode = 0700
  54. // internal fd usage includes disk usage and transport usage.
  55. // To read/write snapshot, snap pkg needs 1. In normal case, wal pkg needs
  56. // at most 2 to read/lock/write WALs. One case that it needs to 2 is to
  57. // read all logs after some snapshot index, which locates at the end of
  58. // the second last and the head of the last. For purging, it needs to read
  59. // directory, so it needs 1. For fd monitor, it needs 1.
  60. // For transport, rafthttp builds two long-polling connections and at most
  61. // four temporary connections with each member. There are at most 9 members
  62. // in a cluster, so it should reserve 96.
  63. // For the safety, we set the total reserved number to 150.
  64. reservedInternalFDNum = 150
  65. )
  66. var (
  67. dirMember = dirType("member")
  68. dirProxy = dirType("proxy")
  69. dirEmpty = dirType("empty")
  70. )
  71. func Main() {
  72. cfg := NewConfig()
  73. err := cfg.Parse(os.Args[1:])
  74. if err != nil {
  75. plog.Errorf("error verifying flags, %v. See 'etcd --help'.", err)
  76. switch err {
  77. case errUnsetAdvertiseClientURLsFlag:
  78. plog.Errorf("When listening on specific address(es), this etcd process must advertise accessible url(s) to each connected client.")
  79. }
  80. os.Exit(1)
  81. }
  82. setupLogging(cfg)
  83. var stopped <-chan struct{}
  84. plog.Infof("etcd Version: %s\n", version.Version)
  85. plog.Infof("Git SHA: %s\n", version.GitSHA)
  86. plog.Infof("Go Version: %s\n", runtime.Version())
  87. plog.Infof("Go OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
  88. GoMaxProcs := runtime.GOMAXPROCS(0)
  89. plog.Infof("setting maximum number of CPUs to %d, total number of available CPUs is %d", GoMaxProcs, runtime.NumCPU())
  90. // TODO: check whether fields are set instead of whether fields have default value
  91. if cfg.name != defaultName && cfg.initialCluster == initialClusterFromName(defaultName) {
  92. cfg.initialCluster = initialClusterFromName(cfg.name)
  93. }
  94. if cfg.dir == "" {
  95. cfg.dir = fmt.Sprintf("%v.etcd", cfg.name)
  96. plog.Warningf("no data-dir provided, using default data-dir ./%s", cfg.dir)
  97. }
  98. which := identifyDataDirOrDie(cfg.dir)
  99. if which != dirEmpty {
  100. plog.Noticef("the server is already initialized as %v before, starting as etcd %v...", which, which)
  101. switch which {
  102. case dirMember:
  103. stopped, err = startEtcd(cfg)
  104. case dirProxy:
  105. err = startProxy(cfg)
  106. default:
  107. plog.Panicf("unhandled dir type %v", which)
  108. }
  109. } else {
  110. shouldProxy := cfg.isProxy()
  111. if !shouldProxy {
  112. stopped, err = startEtcd(cfg)
  113. if derr, ok := err.(*etcdserver.DiscoveryError); ok && derr.Err == discovery.ErrFullCluster {
  114. if cfg.shouldFallbackToProxy() {
  115. plog.Noticef("discovery cluster full, falling back to %s", fallbackFlagProxy)
  116. shouldProxy = true
  117. }
  118. }
  119. }
  120. if shouldProxy {
  121. err = startProxy(cfg)
  122. }
  123. }
  124. if err != nil {
  125. if derr, ok := err.(*etcdserver.DiscoveryError); ok {
  126. switch derr.Err {
  127. case discovery.ErrDuplicateID:
  128. plog.Errorf("member %q has previously registered with discovery service token (%s).", cfg.name, cfg.durl)
  129. plog.Errorf("But etcd could not find valid cluster configuration in the given data dir (%s).", cfg.dir)
  130. plog.Infof("Please check the given data dir path if the previous bootstrap succeeded")
  131. plog.Infof("or use a new discovery token if the previous bootstrap failed.")
  132. case discovery.ErrDuplicateName:
  133. plog.Errorf("member with duplicated name has registered with discovery service token(%s).", cfg.durl)
  134. plog.Errorf("please check (cURL) the discovery token for more information.")
  135. plog.Errorf("please do not reuse the discovery token and generate a new one to bootstrap the cluster.")
  136. default:
  137. plog.Errorf("%v", err)
  138. plog.Infof("discovery token %s was used, but failed to bootstrap the cluster.", cfg.durl)
  139. plog.Infof("please generate a new discovery token and try to bootstrap again.")
  140. }
  141. os.Exit(1)
  142. }
  143. if strings.Contains(err.Error(), "include") && strings.Contains(err.Error(), "--initial-cluster") {
  144. plog.Infof("%v", err)
  145. if cfg.initialCluster == initialClusterFromName(cfg.name) {
  146. plog.Infof("forgot to set --initial-cluster flag?")
  147. }
  148. if types.URLs(cfg.apurls).String() == defaultInitialAdvertisePeerURLs {
  149. plog.Infof("forgot to set --initial-advertise-peer-urls flag?")
  150. }
  151. if cfg.initialCluster == initialClusterFromName(cfg.name) && len(cfg.durl) == 0 {
  152. plog.Infof("if you want to use discovery service, please set --discovery flag.")
  153. }
  154. os.Exit(1)
  155. }
  156. plog.Fatalf("%v", err)
  157. }
  158. osutil.HandleInterrupts()
  159. if systemdutil.IsRunningSystemd() {
  160. // At this point, the initialization of etcd is done.
  161. // The listeners are listening on the TCP ports and ready
  162. // for accepting connections.
  163. // The http server is probably ready for serving incoming
  164. // connections. If it is not, the connection might be pending
  165. // for less than one second.
  166. err := daemon.SdNotify("READY=1")
  167. if err != nil {
  168. plog.Errorf("failed to notify systemd for readiness: %v", err)
  169. if err == daemon.SdNotifyNoSocket {
  170. plog.Errorf("forgot to set Type=notify in systemd service file?")
  171. }
  172. }
  173. }
  174. <-stopped
  175. osutil.Exit(0)
  176. }
  177. // startEtcd launches the etcd server and HTTP handlers for client/server communication.
  178. func startEtcd(cfg *config) (<-chan struct{}, error) {
  179. urlsmap, token, err := getPeerURLsMapAndToken(cfg, "etcd")
  180. if err != nil {
  181. return nil, fmt.Errorf("error setting up initial cluster: %v", err)
  182. }
  183. if cfg.peerAutoTLS && cfg.peerTLSInfo.Empty() {
  184. phosts := make([]string, 0)
  185. for _, u := range cfg.lpurls {
  186. phosts = append(phosts, u.Host)
  187. }
  188. cfg.peerTLSInfo, err = transport.SelfCert(cfg.dir, phosts)
  189. if err != nil {
  190. plog.Fatalf("could not get certs (%v)", err)
  191. }
  192. } else if cfg.peerAutoTLS {
  193. plog.Warningf("ignoring peer auto TLS since certs given")
  194. }
  195. if !cfg.peerTLSInfo.Empty() {
  196. plog.Infof("peerTLS: %s", cfg.peerTLSInfo)
  197. }
  198. plns := make([]net.Listener, 0)
  199. for _, u := range cfg.lpurls {
  200. if u.Scheme == "http" {
  201. if !cfg.peerTLSInfo.Empty() {
  202. plog.Warningf("The scheme of peer url %s is HTTP while peer key/cert files are presented. Ignored peer key/cert files.", u.String())
  203. }
  204. if cfg.peerTLSInfo.ClientCertAuth {
  205. plog.Warningf("The scheme of peer url %s is HTTP while client cert auth (--peer-client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String())
  206. }
  207. }
  208. var (
  209. l net.Listener
  210. tlscfg *tls.Config
  211. )
  212. if !cfg.peerTLSInfo.Empty() {
  213. tlscfg, err = cfg.peerTLSInfo.ServerConfig()
  214. if err != nil {
  215. return nil, err
  216. }
  217. }
  218. l, err = rafthttp.NewListener(u, tlscfg)
  219. if err != nil {
  220. return nil, err
  221. }
  222. urlStr := u.String()
  223. plog.Info("listening for peers on ", urlStr)
  224. defer func() {
  225. if err != nil {
  226. l.Close()
  227. plog.Info("stopping listening for peers on ", urlStr)
  228. }
  229. }()
  230. plns = append(plns, l)
  231. }
  232. var ctlscfg *tls.Config
  233. if !cfg.clientTLSInfo.Empty() {
  234. plog.Infof("clientTLS: %s", cfg.clientTLSInfo)
  235. ctlscfg, err = cfg.clientTLSInfo.ServerConfig()
  236. if err != nil {
  237. return nil, err
  238. }
  239. }
  240. sctxs := make(map[string]*serveCtx)
  241. for _, u := range cfg.lcurls {
  242. if u.Scheme == "http" {
  243. if !cfg.clientTLSInfo.Empty() {
  244. plog.Warningf("The scheme of client url %s is HTTP while peer key/cert files are presented. Ignored key/cert files.", u.String())
  245. }
  246. if cfg.clientTLSInfo.ClientCertAuth {
  247. plog.Warningf("The scheme of client url %s is HTTP while client cert auth (--client-cert-auth) is enabled. Ignored client cert auth for this url.", u.String())
  248. }
  249. }
  250. if u.Scheme == "https" && ctlscfg == nil {
  251. return nil, fmt.Errorf("TLS key/cert (--cert-file, --key-file) must be provided for client url %s with HTTPs scheme", u.String())
  252. }
  253. ctx := &serveCtx{host: u.Host}
  254. if u.Scheme == "https" {
  255. ctx.secure = true
  256. } else {
  257. ctx.insecure = true
  258. }
  259. if sctxs[u.Host] != nil {
  260. if ctx.secure {
  261. sctxs[u.Host].secure = true
  262. }
  263. if ctx.insecure {
  264. sctxs[u.Host].insecure = true
  265. }
  266. continue
  267. }
  268. var l net.Listener
  269. l, err = net.Listen("tcp", u.Host)
  270. if err != nil {
  271. return nil, err
  272. }
  273. var fdLimit uint64
  274. if fdLimit, err = runtimeutil.FDLimit(); err == nil {
  275. if fdLimit <= reservedInternalFDNum {
  276. plog.Fatalf("file descriptor limit[%d] of etcd process is too low, and should be set higher than %d to ensure internal usage", fdLimit, reservedInternalFDNum)
  277. }
  278. l = transport.LimitListener(l, int(fdLimit-reservedInternalFDNum))
  279. }
  280. l, err = transport.NewKeepAliveListener(l, "tcp", nil)
  281. ctx.l = l
  282. if err != nil {
  283. return nil, err
  284. }
  285. plog.Info("listening for client requests on ", u.Host)
  286. defer func() {
  287. if err != nil {
  288. l.Close()
  289. plog.Info("stopping listening for client requests on ", u.Host)
  290. }
  291. }()
  292. sctxs[u.Host] = ctx
  293. }
  294. srvcfg := &etcdserver.ServerConfig{
  295. Name: cfg.name,
  296. ClientURLs: cfg.acurls,
  297. PeerURLs: cfg.apurls,
  298. DataDir: cfg.dir,
  299. DedicatedWALDir: cfg.walDir,
  300. SnapCount: cfg.snapCount,
  301. MaxSnapFiles: cfg.maxSnapFiles,
  302. MaxWALFiles: cfg.maxWalFiles,
  303. InitialPeerURLsMap: urlsmap,
  304. InitialClusterToken: token,
  305. DiscoveryURL: cfg.durl,
  306. DiscoveryProxy: cfg.dproxy,
  307. NewCluster: cfg.isNewCluster(),
  308. ForceNewCluster: cfg.forceNewCluster,
  309. PeerTLSInfo: cfg.peerTLSInfo,
  310. TickMs: cfg.TickMs,
  311. ElectionTicks: cfg.electionTicks(),
  312. AutoCompactionRetention: cfg.autoCompactionRetention,
  313. QuotaBackendBytes: cfg.quotaBackendBytes,
  314. StrictReconfigCheck: cfg.strictReconfigCheck,
  315. EnablePprof: cfg.enablePprof,
  316. }
  317. var s *etcdserver.EtcdServer
  318. s, err = etcdserver.NewServer(srvcfg)
  319. if err != nil {
  320. return nil, err
  321. }
  322. s.Start()
  323. osutil.RegisterInterruptHandler(s.Stop)
  324. if cfg.corsInfo.String() != "" {
  325. plog.Infof("cors = %s", cfg.corsInfo)
  326. }
  327. ch := http.Handler(&cors.CORSHandler{
  328. Handler: etcdhttp.NewClientHandler(s, srvcfg.ReqTimeout()),
  329. Info: cfg.corsInfo,
  330. })
  331. ph := etcdhttp.NewPeerHandler(s)
  332. // Start the peer server in a goroutine
  333. for _, l := range plns {
  334. go func(l net.Listener) {
  335. plog.Fatal(servePeerHTTP(l, ph))
  336. }(l)
  337. }
  338. // Start a client server goroutine for each listen address
  339. for _, sctx := range sctxs {
  340. go func(sctx *serveCtx) {
  341. // read timeout does not work with http close notify
  342. // TODO: https://github.com/golang/go/issues/9524
  343. plog.Fatal(serve(sctx, s, ctlscfg, ch))
  344. }(sctx)
  345. }
  346. return s.StopNotify(), nil
  347. }
  348. // startProxy launches an HTTP proxy for client communication which proxies to other etcd nodes.
  349. func startProxy(cfg *config) error {
  350. pt, err := transport.NewTimeoutTransport(cfg.peerTLSInfo, time.Duration(cfg.proxyDialTimeoutMs)*time.Millisecond, time.Duration(cfg.proxyReadTimeoutMs)*time.Millisecond, time.Duration(cfg.proxyWriteTimeoutMs)*time.Millisecond)
  351. if err != nil {
  352. return err
  353. }
  354. pt.MaxIdleConnsPerHost = proxy.DefaultMaxIdleConnsPerHost
  355. tr, err := transport.NewTimeoutTransport(cfg.peerTLSInfo, time.Duration(cfg.proxyDialTimeoutMs)*time.Millisecond, time.Duration(cfg.proxyReadTimeoutMs)*time.Millisecond, time.Duration(cfg.proxyWriteTimeoutMs)*time.Millisecond)
  356. if err != nil {
  357. return err
  358. }
  359. cfg.dir = path.Join(cfg.dir, "proxy")
  360. err = os.MkdirAll(cfg.dir, 0700)
  361. if err != nil {
  362. return err
  363. }
  364. var peerURLs []string
  365. clusterfile := path.Join(cfg.dir, "cluster")
  366. b, err := ioutil.ReadFile(clusterfile)
  367. switch {
  368. case err == nil:
  369. if cfg.durl != "" {
  370. plog.Warningf("discovery token ignored since the proxy has already been initialized. Valid cluster file found at %q", clusterfile)
  371. }
  372. if cfg.dnsCluster != "" {
  373. plog.Warningf("DNS SRV discovery ignored since the proxy has already been initialized. Valid cluster file found at %q", clusterfile)
  374. }
  375. urls := struct{ PeerURLs []string }{}
  376. err = json.Unmarshal(b, &urls)
  377. if err != nil {
  378. return err
  379. }
  380. peerURLs = urls.PeerURLs
  381. plog.Infof("proxy: using peer urls %v from cluster file %q", peerURLs, clusterfile)
  382. case os.IsNotExist(err):
  383. var urlsmap types.URLsMap
  384. urlsmap, _, err = getPeerURLsMapAndToken(cfg, "proxy")
  385. if err != nil {
  386. return fmt.Errorf("error setting up initial cluster: %v", err)
  387. }
  388. if cfg.durl != "" {
  389. var s string
  390. s, err = discovery.GetCluster(cfg.durl, cfg.dproxy)
  391. if err != nil {
  392. return err
  393. }
  394. if urlsmap, err = types.NewURLsMap(s); err != nil {
  395. return err
  396. }
  397. }
  398. peerURLs = urlsmap.URLs()
  399. plog.Infof("proxy: using peer urls %v ", peerURLs)
  400. default:
  401. return err
  402. }
  403. clientURLs := []string{}
  404. uf := func() []string {
  405. gcls, gerr := etcdserver.GetClusterFromRemotePeers(peerURLs, tr)
  406. // TODO: remove the 2nd check when we fix GetClusterFromRemotePeers
  407. // GetClusterFromRemotePeers should not return nil error with an invalid empty cluster
  408. if gerr != nil {
  409. plog.Warningf("proxy: %v", gerr)
  410. return []string{}
  411. }
  412. if len(gcls.Members()) == 0 {
  413. return clientURLs
  414. }
  415. clientURLs = gcls.ClientURLs()
  416. urls := struct{ PeerURLs []string }{gcls.PeerURLs()}
  417. b, jerr := json.Marshal(urls)
  418. if jerr != nil {
  419. plog.Warningf("proxy: error on marshal peer urls %s", jerr)
  420. return clientURLs
  421. }
  422. err = pkgioutil.WriteAndSyncFile(clusterfile+".bak", b, 0600)
  423. if err != nil {
  424. plog.Warningf("proxy: error on writing urls %s", err)
  425. return clientURLs
  426. }
  427. err = os.Rename(clusterfile+".bak", clusterfile)
  428. if err != nil {
  429. plog.Warningf("proxy: error on updating clusterfile %s", err)
  430. return clientURLs
  431. }
  432. if !reflect.DeepEqual(gcls.PeerURLs(), peerURLs) {
  433. plog.Noticef("proxy: updated peer urls in cluster file from %v to %v", peerURLs, gcls.PeerURLs())
  434. }
  435. peerURLs = gcls.PeerURLs()
  436. return clientURLs
  437. }
  438. ph := proxy.NewHandler(pt, uf, time.Duration(cfg.proxyFailureWaitMs)*time.Millisecond, time.Duration(cfg.proxyRefreshIntervalMs)*time.Millisecond)
  439. ph = &cors.CORSHandler{
  440. Handler: ph,
  441. Info: cfg.corsInfo,
  442. }
  443. if cfg.isReadonlyProxy() {
  444. ph = proxy.NewReadonlyHandler(ph)
  445. }
  446. // Start a proxy server goroutine for each listen address
  447. for _, u := range cfg.lcurls {
  448. var (
  449. l net.Listener
  450. tlscfg *tls.Config
  451. )
  452. if !cfg.clientTLSInfo.Empty() {
  453. tlscfg, err = cfg.clientTLSInfo.ServerConfig()
  454. if err != nil {
  455. return err
  456. }
  457. }
  458. l, err := transport.NewListener(u.Host, u.Scheme, tlscfg)
  459. if err != nil {
  460. return err
  461. }
  462. host := u.String()
  463. go func() {
  464. plog.Info("proxy: listening for client requests on ", host)
  465. mux := http.NewServeMux()
  466. mux.Handle("/metrics", prometheus.Handler())
  467. mux.Handle("/", ph)
  468. plog.Fatal(http.Serve(l, mux))
  469. }()
  470. }
  471. return nil
  472. }
  473. // getPeerURLsMapAndToken sets up an initial peer URLsMap and cluster token for bootstrap or discovery.
  474. func getPeerURLsMapAndToken(cfg *config, which string) (urlsmap types.URLsMap, token string, err error) {
  475. switch {
  476. case cfg.durl != "":
  477. urlsmap = types.URLsMap{}
  478. // If using discovery, generate a temporary cluster based on
  479. // self's advertised peer URLs
  480. urlsmap[cfg.name] = cfg.apurls
  481. token = cfg.durl
  482. case cfg.dnsCluster != "":
  483. var clusterStr string
  484. clusterStr, token, err = discovery.SRVGetCluster(cfg.name, cfg.dnsCluster, cfg.initialClusterToken, cfg.apurls)
  485. if err != nil {
  486. return nil, "", err
  487. }
  488. urlsmap, err = types.NewURLsMap(clusterStr)
  489. // only etcd member must belong to the discovered cluster.
  490. // proxy does not need to belong to the discovered cluster.
  491. if which == "etcd" {
  492. if _, ok := urlsmap[cfg.name]; !ok {
  493. return nil, "", fmt.Errorf("cannot find local etcd member %q in SRV records", cfg.name)
  494. }
  495. }
  496. default:
  497. // We're statically configured, and cluster has appropriately been set.
  498. urlsmap, err = types.NewURLsMap(cfg.initialCluster)
  499. token = cfg.initialClusterToken
  500. }
  501. return urlsmap, token, err
  502. }
  503. // identifyDataDirOrDie returns the type of the data dir.
  504. // Dies if the datadir is invalid.
  505. func identifyDataDirOrDie(dir string) dirType {
  506. names, err := fileutil.ReadDir(dir)
  507. if err != nil {
  508. if os.IsNotExist(err) {
  509. return dirEmpty
  510. }
  511. plog.Fatalf("error listing data dir: %s", dir)
  512. }
  513. var m, p bool
  514. for _, name := range names {
  515. switch dirType(name) {
  516. case dirMember:
  517. m = true
  518. case dirProxy:
  519. p = true
  520. default:
  521. plog.Warningf("found invalid file/dir %s under data dir %s (Ignore this if you are upgrading etcd)", name, dir)
  522. }
  523. }
  524. if m && p {
  525. plog.Fatal("invalid datadir. Both member and proxy directories exist.")
  526. }
  527. if m {
  528. return dirMember
  529. }
  530. if p {
  531. return dirProxy
  532. }
  533. return dirEmpty
  534. }
  535. func setupLogging(cfg *config) {
  536. capnslog.SetGlobalLogLevel(capnslog.INFO)
  537. if cfg.debug {
  538. capnslog.SetGlobalLogLevel(capnslog.DEBUG)
  539. }
  540. if cfg.logPkgLevels != "" {
  541. repoLog := capnslog.MustRepoLogger("github.com/coreos/etcd")
  542. settings, err := repoLog.ParseLogLevelConfig(cfg.logPkgLevels)
  543. if err != nil {
  544. plog.Warningf("couldn't parse log level string: %s, continuing with default levels", err.Error())
  545. return
  546. }
  547. repoLog.SetLogLevel(settings)
  548. }
  549. }