From 315fb56f14fbef24204cc424f95ff49a9ee6149b Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Sun, 29 Jan 2017 14:01:38 -0500 Subject: [PATCH] fix templated services --- services/boot/arvados_go.go | 32 +++++++++++++++++++++++++------- services/boot/booter.go | 9 ++++++++- services/boot/consul.go | 2 +- services/boot/supervisor.go | 2 +- services/boot/vault.go | 2 +- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/services/boot/arvados_go.go b/services/boot/arvados_go.go index 8a4a10d15b..e23a1d1403 100644 --- a/services/boot/arvados_go.go +++ b/services/boot/arvados_go.go @@ -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, }, diff --git a/services/boot/booter.go b/services/boot/booter.go index 3ca800db5e..ee37fd0fe6 100644 --- a/services/boot/booter.go +++ b/services/boot/booter.go @@ -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() diff --git a/services/boot/consul.go b/services/boot/consul.go index 6ad5e6e695..d5e63017ee 100644 --- a/services/boot/consul.go +++ b/services/boot/consul.go @@ -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 diff --git a/services/boot/supervisor.go b/services/boot/supervisor.go index 2fcb33613d..9ac2532c8f 100644 --- a/services/boot/supervisor.go +++ b/services/boot/supervisor.go @@ -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 { diff --git a/services/boot/vault.go b/services/boot/vault.go index 85b062a4d3..de9cfb3c15 100644 --- a/services/boot/vault.go +++ b/services/boot/vault.go @@ -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 -- 2.30.2