add vault, consul-template, arvados pkgs
[arvados.git] / services / boot / consul.go
index 8761b39ae4770da3ec19c34e1b220a1b5bf64143..e1015ae59d07c37a4ad5efb7b93642798f98ac0f 100644 (file)
@@ -20,6 +20,9 @@ func (cb *consulBooter) Boot(ctx context.Context) error {
        cb.Lock()
        defer cb.Unlock()
 
+       if cb.check(ctx) == nil {
+               return nil
+       }
        cfg := cfg(ctx)
        bin := cfg.UsrDir + "/bin/consul"
        err := (&download{
@@ -31,9 +34,6 @@ func (cb *consulBooter) Boot(ctx context.Context) error {
        if err != nil {
                return err
        }
-       if cb.check(ctx) == nil {
-               return nil
-       }
        dataDir := cfg.DataDir + "/consul"
        if err := os.MkdirAll(dataDir, 0700); err != nil {
                return err
@@ -41,7 +41,11 @@ func (cb *consulBooter) Boot(ctx context.Context) error {
        args := []string{
                "agent",
                "-server",
-               "-advertise=127.0.0.1",
+               "-datacenter=" + cfg.SiteID,
+               "-dns-port=" + fmt.Sprintf("%d", cfg.Ports.ConsulDNS),
+               "-http-port=" + fmt.Sprintf("%d", cfg.Ports.ConsulHTTP),
+               "-serf-lan-bind=0.0.0.0:" + fmt.Sprintf("%d", cfg.Ports.ConsulSerfLAN),
+               "-serf-wan-bind=0.0.0.0:" + fmt.Sprintf("%d", cfg.Ports.ConsulSerfWAN),
                "-data-dir", dataDir,
                "-bootstrap-expect", fmt.Sprintf("%d", len(cfg.ControlHosts))}
        supervisor := newSupervisor(ctx, "consul", bin, args...)
@@ -72,6 +76,7 @@ var consulCfg = api.DefaultConfig()
 
 func (cb *consulBooter) check(ctx context.Context) error {
        cfg := cfg(ctx)
+       consulCfg.Address = fmt.Sprintf("127.0.0.1:%d", cfg.Ports.ConsulHTTP)
        consulCfg.Datacenter = cfg.SiteID
        consul, err := api.NewClient(consulCfg)
        if err != nil {