From 8e9ccb0422b09e8cf2b7811267a2dc1ed2cb02af Mon Sep 17 00:00:00 2001 From: jaffee Date: Wed, 25 Jan 2017 15:16:29 -0600 Subject: [PATCH] use temp location for pilosactl and pilosa binaries I did it this way instead of using mktemp because a) mktemp would have created a different filename on every host, which would make the client side logic much more confusing b) mktemp isn't guaranteed to be available everywhere, so we're not losing much by assuming /tmp exists. --- cmd/pilosactl/main.go | 10 +++++----- creator/remote.go | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/pilosactl/main.go b/cmd/pilosactl/main.go index 4e349bd45..331459c31 100644 --- a/cmd/pilosactl/main.go +++ b/cmd/pilosactl/main.go @@ -14,7 +14,6 @@ import ( "math/rand" "os" "os/signal" - "path" "path/filepath" "sort" "strconv" @@ -1542,15 +1541,16 @@ func (cmd *BspawnCommand) spawnRemote(ctx context.Context) (map[string]interface return nil, err } + cmdName := "pilosactl" if cmd.CopyBinary { - fmt.Fprintf(cmd.Stderr, "bspawn: building pilosactl binary with GOOS=%v and GOARCH=%v to copy to agent hosts\n", cmd.GOOS, cmd.GOARCH) + cmdName = "/tmp/pilosactl" + strconv.Itoa(rand.Int()) + fmt.Fprintf(cmd.Stderr, "bspawn: building pilosactl binary with GOOS=%v and GOARCH=%v to copy to agents at %v\n", cmd.GOOS, cmd.GOARCH, cmdName) pkg := "github.com/pilosa/pilosa/cmd/pilosactl" bin, err := build.Binary(pkg, cmd.GOOS, cmd.GOARCH) if err != nil { return nil, err } - - err = agentFleet.WriteFile(path.Base(pkg), "+x", bin) + err = agentFleet.WriteFile(cmdName, "+x", bin) if err != nil { return nil, err } @@ -1589,7 +1589,7 @@ func (cmd *BspawnCommand) spawnRemote(ctx context.Context) (map[string]interface resLock.Unlock() }(stdout, sp.Name, i) sess.Stderr = cmd.Stderr - err = sess.Start("PATH=.:$PATH pilosactl bagent -agent-num=" + strconv.Itoa(i) + " -hosts=" + strings.Join(cmd.PilosaHosts, ",") + " " + strings.Join(sp.Args, " ")) + err = sess.Start(cmdName + " bagent -agent-num=" + strconv.Itoa(i) + " -hosts=" + strings.Join(cmd.PilosaHosts, ",") + " " + strings.Join(sp.Args, " ")) if err != nil { return nil, err } diff --git a/creator/remote.go b/creator/remote.go index 552b49d84..ebd3a5bcf 100644 --- a/creator/remote.go +++ b/creator/remote.go @@ -3,11 +3,10 @@ package creator import ( "fmt" "io" + "math/rand" "net" - "path" "strconv" "sync" - "time" "github.com/BurntSushi/toml" @@ -48,8 +47,10 @@ func (c *RemoteCluster) Start() error { if err != nil { return fmt.Errorf("connecting to cluster hosts: %v", err) } + cmdName := "pilosa" if c.CopyBinary { - fmt.Fprintf(c.Stderr, "create: building pilosa binary with GOOS=%v and GOARCH=%v to copy to hosts", c.GOOS, c.GOARCH) + cmdName = "/tmp/pilosa" + strconv.Itoa(rand.Int()) + fmt.Fprintf(c.Stderr, "create: building pilosa binary with GOOS=%v and GOARCH=%v to copy to hosts at %v", c.GOOS, c.GOARCH, cmdName) pkg := "github.com/pilosa/pilosa/cmd/pilosa" bin, err := build.Binary(pkg, c.GOOS, c.GOARCH) @@ -57,7 +58,7 @@ func (c *RemoteCluster) Start() error { return fmt.Errorf("building binary: %v", err) } - err = fleet.WriteFile(path.Base(pkg), "+x", bin) + err = fleet.WriteFile(cmdName, "+x", bin) if err != nil { return fmt.Errorf("writing binary to fleet: %v", err) } @@ -133,7 +134,7 @@ func (c *RemoteCluster) Start() error { gomaxprocsString = "GOMAXPROCS=" + strconv.Itoa(c.GoMaxProcs) + " " } - err = sess.Start("PATH=.:$PATH " + gomaxprocsString + "pilosa -config " + configname) + err = sess.Start(gomaxprocsString + cmdName + " -config " + configname) if err != nil { return err }