fix templated services
authorTom Clegg <tom@curoverse.com>
Sun, 29 Jan 2017 19:01:38 +0000 (14:01 -0500)
committerTom Clegg <tom@curoverse.com>
Sun, 29 Jan 2017 19:01:38 +0000 (14:01 -0500)
services/boot/arvados_go.go
services/boot/booter.go
services/boot/consul.go
services/boot/supervisor.go
services/boot/vault.go

index 8a4a10d15b440c55de876a7702b0ceab76633ace..e23a1d1403d6371169f677d3206d0162033fc2da 100644 (file)
@@ -2,6 +2,7 @@ package main
 
 import (
        "context"
+       "fmt"
        "log"
        "math/rand"
        "os"
@@ -12,15 +13,19 @@ import (
 var (
        dispatchLocal = &arvadosGoBooter{name: "crunch-dispatch-local"}
        dispatchSLURM = &arvadosGoBooter{name: "crunch-dispatch-slurm"}
-       gitHTTP       = &arvadosGoBooter{name: "arvados-git-httpd"}
-       keepbalance   = &arvadosGoBooter{name: "keep-balance"}
+       gitHTTP       = &arvadosGoBooter{name: "arvados-git-httpd", conf: "git-httpd"}
+       keepbalance   = &arvadosGoBooter{name: "keep-balance", tmpl: keepbalanceTmpl}
        keepproxy     = &arvadosGoBooter{name: "keepproxy"}
        keepstore     = &arvadosGoBooter{name: "keepstore"}
-       websocket     = &arvadosGoBooter{name: "arvados-ws"}
+       websocket     = &arvadosGoBooter{name: "arvados-ws", conf: "ws"}
+
+       keepbalanceTmpl = `{"RunPeriod":"1m"}`
 )
 
 type arvadosGoBooter struct {
        name string
+       conf string
+       tmpl string
 }
 
 func availablePort() int {
@@ -29,6 +34,14 @@ func availablePort() int {
 
 func (agb *arvadosGoBooter) Boot(ctx context.Context) error {
        cfg := cfg(ctx)
+
+       if agb.conf == "" {
+               agb.conf = agb.name
+       }
+       if agb.tmpl == "" {
+               agb.tmpl = "{}"
+       }
+
        cmd := path.Join(cfg.UsrDir, "bin", agb.name)
        if _, err := os.Stat(cmd); err != nil {
                if found, err := filepath.Glob(path.Join(cfg.UsrDir, "pkg", agb.name+"_*.deb")); err == nil && len(found) > 0 {
@@ -41,8 +54,13 @@ func (agb *arvadosGoBooter) Boot(ctx context.Context) error {
                        }
                }
        }
-       cfgPath := path.Join("/etc/arvados", agb.name, agb.name+".yml")
-       atomicWriteFile(cfgPath+".ctmpl", []byte("{}"), 0644)
+       cfgPath := path.Join("/etc/arvados", agb.conf, agb.conf+".yml")
+       if err := os.MkdirAll(path.Dir(cfgPath), 0755); err != nil {
+               return err
+       }
+       if err := atomicWriteFile(cfgPath+".ctmpl", []byte("{}"), 0644); err != nil {
+               return err
+       }
        return Series{
                &osPackage{
                        Debian: agb.name,
@@ -51,8 +69,8 @@ func (agb *arvadosGoBooter) Boot(ctx context.Context) error {
                        name: agb.name,
                        cmd:  path.Join(cfg.UsrDir, "bin", "consul-template"),
                        args: []string{
-                               "-consul-addr=127.0.0.1:8500",
-                               "-template="+cfgPath+".ctmpl:"+cfgPath,
+                               "-consul-addr=" + fmt.Sprintf("0.0.0.0:%d", cfg.Ports.ConsulHTTP),
+                               "-template=" + cfgPath + ".ctmpl:" + cfgPath,
                                "-exec",
                                agb.name,
                        },
index 3ca800db5e745deee57d4bd79230b2387dad6494..ee37fd0fe616418974d81a7cec96559c60b0b8c8 100644 (file)
@@ -45,7 +45,14 @@ func (cb Concurrent) Boot(ctx context.Context) error {
                i, b := i, b
                go func() {
                        defer wg.Done()
-                       errs[i] = b.Boot(ctx)
+                       err := b.Boot(ctx)
+                       switch err.(type) {
+                       case nil:
+                       case *MultipleError:
+                       default:
+                               err = fmt.Errorf("%T: %s", b, err)
+                       }
+                       errs[i] = err
                }()
        }
        wg.Wait()
index 6ad5e6e69551f94718b1745c580613cc04205a25..d5e63017eec6fcb461cb6c99bac694c35dcae3ba 100644 (file)
@@ -80,7 +80,7 @@ func (cb *consulBooter) Boot(ctx context.Context) error {
                }
                args = append(args, "-config-file="+cf)
        }
-       supervisor := newSupervisor(ctx, "consul", bin, args...)
+       supervisor := newSupervisor(ctx, "arvados-consul", bin, args...)
        running, err := supervisor.Running(ctx)
        if err != nil {
                return err
index 2fcb33613d70e34337d833b0f13368f5a3f5bcb1..9ac2532c8fdf32b0e060cd7cca7c3a262dfd39a0 100644 (file)
@@ -42,7 +42,7 @@ func (s *supervisedService) Boot(ctx context.Context) error {
        if _, err := os.Stat(bin); err != nil {
                return err
        }
-       sup := newSupervisor(ctx, s.name, bin)
+       sup := newSupervisor(ctx, s.name, bin, s.args...)
        if ok, err := sup.Running(ctx); err != nil {
                return err
        } else if !ok {
index 85b062a4d342429d525147360cccb413b7af83df..de9cfb3c154a63b01df78aee1522f57b20c90260 100644 (file)
@@ -53,7 +53,7 @@ func (vb *vaultBooter) Boot(ctx context.Context) error {
        }
 
        args := []string{"server", "-config=" + cfgPath}
-       supervisor := newSupervisor(ctx, "vault", bin, args...)
+       supervisor := newSupervisor(ctx, "arvados-vault", bin, args...)
        running, err := supervisor.Running(ctx)
        if err != nil {
                return err