X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9a7e2a24f5f3d261e554ac3815b7e2a4c2e24503..42bf31f017a009585eaac2fe44a83b2596b3e5c8:/lib/dispatchcloud/worker/runner.go diff --git a/lib/dispatchcloud/worker/runner.go b/lib/dispatchcloud/worker/runner.go index c30ff9f2b7..0fd99aeeef 100644 --- a/lib/dispatchcloud/worker/runner.go +++ b/lib/dispatchcloud/worker/runner.go @@ -8,10 +8,10 @@ import ( "bytes" "encoding/json" "fmt" + "net" "syscall" "time" - "git.curoverse.com/arvados.git/sdk/go/arvados" "github.com/sirupsen/logrus" ) @@ -20,7 +20,8 @@ import ( type remoteRunner struct { uuid string executor Executor - arvClient *arvados.Client + envJSON json.RawMessage + runnerCmd string remoteUser string timeoutTERM time.Duration timeoutSignal time.Duration @@ -36,10 +37,33 @@ type remoteRunner struct { // newRemoteRunner returns a new remoteRunner. Caller should ensure // Close() is called to release resources. func newRemoteRunner(uuid string, wkr *worker) *remoteRunner { + // Send the instance type record as a JSON doc so crunch-run + // can log it. + var instJSON bytes.Buffer + enc := json.NewEncoder(&instJSON) + enc.SetIndent("", " ") + if err := enc.Encode(wkr.instType); err != nil { + panic(err) + } + env := map[string]string{ + "ARVADOS_API_HOST": wkr.wp.arvClient.APIHost, + "ARVADOS_API_TOKEN": wkr.wp.arvClient.AuthToken, + "InstanceType": instJSON.String(), + "GatewayAddress": net.JoinHostPort(wkr.instance.Address(), "0"), + "GatewayAuthSecret": wkr.wp.gatewayAuthSecret(uuid), + } + if wkr.wp.arvClient.Insecure { + env["ARVADOS_API_HOST_INSECURE"] = "1" + } + envJSON, err := json.Marshal(env) + if err != nil { + panic(err) + } rr := &remoteRunner{ uuid: uuid, executor: wkr.executor, - arvClient: wkr.wp.arvClient, + envJSON: envJSON, + runnerCmd: wkr.wp.runnerCmd, remoteUser: wkr.instance.RemoteUser(), timeoutTERM: wkr.wp.timeoutTERM, timeoutSignal: wkr.wp.timeoutSignal, @@ -57,22 +81,11 @@ func newRemoteRunner(uuid string, wkr *worker) *remoteRunner { // assume the remote process _might_ have started, at least until it // probes the worker and finds otherwise. func (rr *remoteRunner) Start() { - env := map[string]string{ - "ARVADOS_API_HOST": rr.arvClient.APIHost, - "ARVADOS_API_TOKEN": rr.arvClient.AuthToken, - } - if rr.arvClient.Insecure { - env["ARVADOS_API_HOST_INSECURE"] = "1" - } - envJSON, err := json.Marshal(env) - if err != nil { - panic(err) - } - stdin := bytes.NewBuffer(envJSON) - cmd := "crunch-run --detach --stdin-env '" + rr.uuid + "'" + cmd := rr.runnerCmd + " --detach --stdin-env '" + rr.uuid + "'" if rr.remoteUser != "root" { cmd = "sudo " + cmd } + stdin := bytes.NewBuffer(rr.envJSON) stdout, stderr, err := rr.executor.Execute(nil, cmd, stdin) if err != nil { rr.logger.WithField("stdout", string(stdout)). @@ -128,7 +141,7 @@ func (rr *remoteRunner) Kill(reason string) { func (rr *remoteRunner) kill(sig syscall.Signal) { logger := rr.logger.WithField("Signal", int(sig)) logger.Info("sending signal") - cmd := fmt.Sprintf("crunch-run --kill %d %s", sig, rr.uuid) + cmd := fmt.Sprintf(rr.runnerCmd+" --kill %d %s", sig, rr.uuid) if rr.remoteUser != "root" { cmd = "sudo " + cmd }