8 "git.curoverse.com/arvados.git/lib/crunchstat"
9 "git.curoverse.com/arvados.git/sdk/go/arvados"
10 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
11 "git.curoverse.com/arvados.git/sdk/go/keepclient"
12 "git.curoverse.com/arvados.git/sdk/go/manifest"
13 "github.com/curoverse/dockerclient"
28 // IArvadosClient is the minimal Arvados API methods used by crunch-run.
29 type IArvadosClient interface {
30 Create(resourceType string, parameters arvadosclient.Dict, output interface{}) error
31 Get(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) error
32 Update(resourceType string, uuid string, parameters arvadosclient.Dict, output interface{}) (err error)
33 Call(method, resourceType, uuid, action string, parameters arvadosclient.Dict, output interface{}) (err error)
36 // ErrCancelled is the error returned when the container is cancelled.
37 var ErrCancelled = errors.New("Cancelled")
39 // IKeepClient is the minimal Keep API methods used by crunch-run.
40 type IKeepClient interface {
41 PutHB(hash string, buf []byte) (string, int, error)
42 ManifestFileReader(m manifest.Manifest, filename string) (keepclient.ReadCloserWithLen, error)
45 // NewLogWriter is a factory function to create a new log writer.
46 type NewLogWriter func(name string) io.WriteCloser
48 type RunArvMount func(args []string, tok string) (*exec.Cmd, error)
50 type MkTempDir func(string, string) (string, error)
52 // ThinDockerClient is the minimal Docker client interface used by crunch-run.
53 type ThinDockerClient interface {
54 StopContainer(id string, timeout int) error
55 InspectImage(id string) (*dockerclient.ImageInfo, error)
56 LoadImage(reader io.Reader) error
57 CreateContainer(config *dockerclient.ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (string, error)
58 StartContainer(id string, config *dockerclient.HostConfig) error
59 AttachContainer(id string, options *dockerclient.AttachOptions) (io.ReadCloser, error)
60 Wait(id string) <-chan dockerclient.WaitResult
61 RemoveImage(name string, force bool) ([]*dockerclient.ImageDelete, error)
64 // ContainerRunner is the main stateful struct used for a single execution of a
66 type ContainerRunner struct {
67 Docker ThinDockerClient
68 ArvClient IArvadosClient
71 dockerclient.ContainerConfig
72 dockerclient.HostConfig
78 CrunchLog *ThrottledLogger
80 Stderr *ThrottledLogger
81 LogCollection *CollectionWriter
88 CleanupTempDir []string
93 SigChan chan os.Signal
94 ArvMountExit chan error
97 statLogger io.WriteCloser
98 statReporter *crunchstat.Reporter
99 statInterval time.Duration
104 // SetupSignals sets up signal handling to gracefully terminate the underlying
105 // Docker container and update state when receiving a TERM, INT or QUIT signal.
106 func (runner *ContainerRunner) SetupSignals() {
107 runner.SigChan = make(chan os.Signal, 1)
108 signal.Notify(runner.SigChan, syscall.SIGTERM)
109 signal.Notify(runner.SigChan, syscall.SIGINT)
110 signal.Notify(runner.SigChan, syscall.SIGQUIT)
112 go func(sig <-chan os.Signal) {
114 if !runner.Cancelled {
115 runner.CancelLock.Lock()
116 runner.Cancelled = true
117 if runner.ContainerID != "" {
118 runner.Docker.StopContainer(runner.ContainerID, 10)
120 runner.CancelLock.Unlock()
126 // LoadImage determines the docker image id from the container record and
127 // checks if it is available in the local Docker image store. If not, it loads
128 // the image from Keep.
129 func (runner *ContainerRunner) LoadImage() (err error) {
131 runner.CrunchLog.Printf("Fetching Docker image from collection '%s'", runner.Container.ContainerImage)
133 var collection arvados.Collection
134 err = runner.ArvClient.Get("collections", runner.Container.ContainerImage, nil, &collection)
136 return fmt.Errorf("While getting container image collection: %v", err)
138 manifest := manifest.Manifest{Text: collection.ManifestText}
139 var img, imageID string
140 for ms := range manifest.StreamIter() {
141 img = ms.FileStreamSegments[0].Name
142 if !strings.HasSuffix(img, ".tar") {
143 return fmt.Errorf("First file in the container image collection does not end in .tar")
145 imageID = img[:len(img)-4]
148 runner.CrunchLog.Printf("Using Docker image id '%s'", imageID)
150 _, err = runner.Docker.InspectImage(imageID)
152 runner.CrunchLog.Print("Loading Docker image from keep")
154 var readCloser io.ReadCloser
155 readCloser, err = runner.Kc.ManifestFileReader(manifest, img)
157 return fmt.Errorf("While creating ManifestFileReader for container image: %v", err)
160 err = runner.Docker.LoadImage(readCloser)
162 return fmt.Errorf("While loading container image into Docker: %v", err)
165 runner.CrunchLog.Print("Docker image is available")
168 runner.ContainerConfig.Image = imageID
173 func (runner *ContainerRunner) ArvMountCmd(arvMountCmd []string, token string) (c *exec.Cmd, err error) {
174 c = exec.Command("arv-mount", arvMountCmd...)
176 // Copy our environment, but override ARVADOS_API_TOKEN with
177 // the container auth token.
179 for _, s := range os.Environ() {
180 if !strings.HasPrefix(s, "ARVADOS_API_TOKEN=") {
181 c.Env = append(c.Env, s)
184 c.Env = append(c.Env, "ARVADOS_API_TOKEN="+token)
186 nt := NewThrottledLogger(runner.NewLogWriter("arv-mount"))
195 statReadme := make(chan bool)
196 runner.ArvMountExit = make(chan error)
201 time.Sleep(100 * time.Millisecond)
202 _, err = os.Stat(fmt.Sprintf("%s/by_id/README", runner.ArvMountPoint))
212 runner.ArvMountExit <- c.Wait()
213 close(runner.ArvMountExit)
219 case err := <-runner.ArvMountExit:
220 runner.ArvMount = nil
228 func (runner *ContainerRunner) SetupMounts() (err error) {
229 runner.ArvMountPoint, err = runner.MkTempDir("", "keep")
231 return fmt.Errorf("While creating keep mount temp dir: %v", err)
234 runner.CleanupTempDir = append(runner.CleanupTempDir, runner.ArvMountPoint)
238 arvMountCmd := []string{"--foreground", "--allow-other", "--read-write"}
239 collectionPaths := []string{}
242 for bind, mnt := range runner.Container.Mounts {
243 if bind == "stdout" {
244 // Is it a "file" mount kind?
245 if mnt.Kind != "file" {
246 return fmt.Errorf("Unsupported mount kind '%s' for stdout. Only 'file' is supported.", mnt.Kind)
249 // Does path start with OutputPath?
250 prefix := runner.Container.OutputPath
251 if !strings.HasSuffix(prefix, "/") {
254 if !strings.HasPrefix(mnt.Path, prefix) {
255 return fmt.Errorf("Stdout path does not start with OutputPath: %s, %s", mnt.Path, prefix)
260 case mnt.Kind == "collection":
262 if mnt.UUID != "" && mnt.PortableDataHash != "" {
263 return fmt.Errorf("Cannot specify both 'uuid' and 'portable_data_hash' for a collection mount")
267 return fmt.Errorf("Writing to existing collections currently not permitted.")
270 src = fmt.Sprintf("%s/by_id/%s", runner.ArvMountPoint, mnt.UUID)
271 } else if mnt.PortableDataHash != "" {
273 return fmt.Errorf("Can never write to a collection specified by portable data hash")
275 src = fmt.Sprintf("%s/by_id/%s", runner.ArvMountPoint, mnt.PortableDataHash)
277 src = fmt.Sprintf("%s/tmp%d", runner.ArvMountPoint, tmpcount)
278 arvMountCmd = append(arvMountCmd, "--mount-tmp")
279 arvMountCmd = append(arvMountCmd, fmt.Sprintf("tmp%d", tmpcount))
283 if bind == runner.Container.OutputPath {
284 runner.HostOutputDir = src
286 runner.Binds = append(runner.Binds, fmt.Sprintf("%s:%s", src, bind))
288 runner.Binds = append(runner.Binds, fmt.Sprintf("%s:%s:ro", src, bind))
290 collectionPaths = append(collectionPaths, src)
292 case mnt.Kind == "tmp" && bind == runner.Container.OutputPath:
293 runner.HostOutputDir, err = runner.MkTempDir("", "")
295 return fmt.Errorf("While creating mount temp dir: %v", err)
297 st, staterr := os.Stat(runner.HostOutputDir)
299 return fmt.Errorf("While Stat on temp dir: %v", staterr)
301 err = os.Chmod(runner.HostOutputDir, st.Mode()|os.ModeSetgid|0777)
303 return fmt.Errorf("While Chmod temp dir: %v", err)
305 runner.CleanupTempDir = append(runner.CleanupTempDir, runner.HostOutputDir)
306 runner.Binds = append(runner.Binds, fmt.Sprintf("%s:%s", runner.HostOutputDir, bind))
308 case mnt.Kind == "tmp":
309 runner.Binds = append(runner.Binds, bind)
311 case mnt.Kind == "json":
312 jsondata, err := json.Marshal(mnt.Content)
314 return fmt.Errorf("encoding json data: %v", err)
316 // Create a tempdir with a single file
317 // (instead of just a tempfile): this way we
318 // can ensure the file is world-readable
319 // inside the container, without having to
320 // make it world-readable on the docker host.
321 tmpdir, err := runner.MkTempDir("", "")
323 return fmt.Errorf("creating temp dir: %v", err)
325 runner.CleanupTempDir = append(runner.CleanupTempDir, tmpdir)
326 tmpfn := filepath.Join(tmpdir, "mountdata.json")
327 err = ioutil.WriteFile(tmpfn, jsondata, 0644)
329 return fmt.Errorf("writing temp file: %v", err)
331 runner.Binds = append(runner.Binds, fmt.Sprintf("%s:%s:ro", tmpfn, bind))
335 if runner.HostOutputDir == "" {
336 return fmt.Errorf("Output path does not correspond to a writable mount point")
340 arvMountCmd = append(arvMountCmd, "--mount-by-pdh", "by_id")
342 arvMountCmd = append(arvMountCmd, "--mount-by-id", "by_id")
344 arvMountCmd = append(arvMountCmd, runner.ArvMountPoint)
346 token, err := runner.ContainerToken()
348 return fmt.Errorf("could not get container token: %s", err)
351 runner.ArvMount, err = runner.RunArvMount(arvMountCmd, token)
353 return fmt.Errorf("While trying to start arv-mount: %v", err)
356 for _, p := range collectionPaths {
359 return fmt.Errorf("While checking that input files exist: %v", err)
366 func (runner *ContainerRunner) ProcessDockerAttach(containerReader io.Reader) {
367 // Handle docker log protocol
368 // https://docs.docker.com/engine/reference/api/docker_remote_api_v1.15/#attach-to-a-container
370 header := make([]byte, 8)
372 _, readerr := io.ReadAtLeast(containerReader, header, 8)
375 readsize := int64(header[7]) | (int64(header[6]) << 8) | (int64(header[5]) << 16) | (int64(header[4]) << 24)
378 _, readerr = io.CopyN(runner.Stdout, containerReader, readsize)
381 _, readerr = io.CopyN(runner.Stderr, containerReader, readsize)
386 if readerr != io.EOF {
387 runner.CrunchLog.Printf("While reading docker logs: %v", readerr)
390 closeerr := runner.Stdout.Close()
392 runner.CrunchLog.Printf("While closing stdout logs: %v", closeerr)
395 closeerr = runner.Stderr.Close()
397 runner.CrunchLog.Printf("While closing stderr logs: %v", closeerr)
400 if runner.statReporter != nil {
401 runner.statReporter.Stop()
402 closeerr = runner.statLogger.Close()
404 runner.CrunchLog.Printf("While closing crunchstat logs: %v", closeerr)
408 runner.loggingDone <- true
409 close(runner.loggingDone)
415 func (runner *ContainerRunner) StartCrunchstat() {
416 runner.statLogger = NewThrottledLogger(runner.NewLogWriter("crunchstat"))
417 runner.statReporter = &crunchstat.Reporter{
418 CID: runner.ContainerID,
419 Logger: log.New(runner.statLogger, "", 0),
420 CgroupParent: runner.cgroupParent,
421 CgroupRoot: runner.cgroupRoot,
422 PollPeriod: runner.statInterval,
424 runner.statReporter.Start()
427 // AttachLogs connects the docker container stdout and stderr logs to the
428 // Arvados logger which logs to Keep and the API server logs table.
429 func (runner *ContainerRunner) AttachStreams() (err error) {
431 runner.CrunchLog.Print("Attaching container streams")
433 var containerReader io.Reader
434 containerReader, err = runner.Docker.AttachContainer(runner.ContainerID,
435 &dockerclient.AttachOptions{Stream: true, Stdout: true, Stderr: true})
437 return fmt.Errorf("While attaching container stdout/stderr streams: %v", err)
440 runner.loggingDone = make(chan bool)
442 if stdoutMnt, ok := runner.Container.Mounts["stdout"]; ok {
443 stdoutPath := stdoutMnt.Path[len(runner.Container.OutputPath):]
444 index := strings.LastIndex(stdoutPath, "/")
446 subdirs := stdoutPath[:index]
448 st, err := os.Stat(runner.HostOutputDir)
450 return fmt.Errorf("While Stat on temp dir: %v", err)
452 stdoutPath := path.Join(runner.HostOutputDir, subdirs)
453 err = os.MkdirAll(stdoutPath, st.Mode()|os.ModeSetgid|0777)
455 return fmt.Errorf("While MkdirAll %q: %v", stdoutPath, err)
459 stdoutFile, err := os.Create(path.Join(runner.HostOutputDir, stdoutPath))
461 return fmt.Errorf("While creating stdout file: %v", err)
463 runner.Stdout = stdoutFile
465 runner.Stdout = NewThrottledLogger(runner.NewLogWriter("stdout"))
467 runner.Stderr = NewThrottledLogger(runner.NewLogWriter("stderr"))
469 go runner.ProcessDockerAttach(containerReader)
474 // CreateContainer creates the docker container.
475 func (runner *ContainerRunner) CreateContainer() error {
476 runner.CrunchLog.Print("Creating Docker container")
478 runner.ContainerConfig.Cmd = runner.Container.Command
479 if runner.Container.Cwd != "." {
480 runner.ContainerConfig.WorkingDir = runner.Container.Cwd
483 for k, v := range runner.Container.Environment {
484 runner.ContainerConfig.Env = append(runner.ContainerConfig.Env, k+"="+v)
486 if wantAPI := runner.Container.RuntimeConstraints.API; wantAPI != nil && *wantAPI {
487 tok, err := runner.ContainerToken()
491 runner.ContainerConfig.Env = append(runner.ContainerConfig.Env,
492 "ARVADOS_API_TOKEN="+tok,
493 "ARVADOS_API_HOST="+os.Getenv("ARVADOS_API_HOST"),
494 "ARVADOS_API_HOST_INSECURE="+os.Getenv("ARVADOS_API_HOST_INSECURE"),
496 runner.ContainerConfig.NetworkDisabled = false
498 runner.ContainerConfig.NetworkDisabled = true
502 runner.ContainerID, err = runner.Docker.CreateContainer(&runner.ContainerConfig, "", nil)
504 return fmt.Errorf("While creating container: %v", err)
507 runner.HostConfig = dockerclient.HostConfig{Binds: runner.Binds,
508 LogConfig: dockerclient.LogConfig{Type: "none"}}
510 return runner.AttachStreams()
513 // StartContainer starts the docker container created by CreateContainer.
514 func (runner *ContainerRunner) StartContainer() error {
515 runner.CrunchLog.Printf("Starting Docker container id '%s'", runner.ContainerID)
516 err := runner.Docker.StartContainer(runner.ContainerID, &runner.HostConfig)
518 return fmt.Errorf("could not start container: %v", err)
523 // WaitFinish waits for the container to terminate, capture the exit code, and
524 // close the stdout/stderr logging.
525 func (runner *ContainerRunner) WaitFinish() error {
526 runner.CrunchLog.Print("Waiting for container to finish")
528 result := runner.Docker.Wait(runner.ContainerID)
531 return fmt.Errorf("While waiting for container to finish: %v", wr.Error)
533 runner.ExitCode = &wr.ExitCode
535 // wait for stdout/stderr to complete
541 // HandleOutput sets the output, unmounts the FUSE mount, and deletes temporary directories
542 func (runner *ContainerRunner) CaptureOutput() error {
543 if runner.finalState != "Complete" {
547 if runner.HostOutputDir == "" {
551 _, err := os.Stat(runner.HostOutputDir)
553 return fmt.Errorf("While checking host output path: %v", err)
556 var manifestText string
558 collectionMetafile := fmt.Sprintf("%s/.arvados#collection", runner.HostOutputDir)
559 _, err = os.Stat(collectionMetafile)
562 cw := CollectionWriter{runner.Kc, nil, sync.Mutex{}}
563 manifestText, err = cw.WriteTree(runner.HostOutputDir, runner.CrunchLog.Logger)
565 return fmt.Errorf("While uploading output files: %v", err)
568 // FUSE mount directory
569 file, openerr := os.Open(collectionMetafile)
571 return fmt.Errorf("While opening FUSE metafile: %v", err)
575 var rec arvados.Collection
576 err = json.NewDecoder(file).Decode(&rec)
578 return fmt.Errorf("While reading FUSE metafile: %v", err)
580 manifestText = rec.ManifestText
583 var response arvados.Collection
584 err = runner.ArvClient.Create("collections",
586 "collection": arvadosclient.Dict{
587 "manifest_text": manifestText}},
590 return fmt.Errorf("While creating output collection: %v", err)
593 runner.OutputPDH = new(string)
594 *runner.OutputPDH = response.PortableDataHash
599 func (runner *ContainerRunner) CleanupDirs() {
600 if runner.ArvMount != nil {
601 umount := exec.Command("fusermount", "-z", "-u", runner.ArvMountPoint)
602 umnterr := umount.Run()
604 runner.CrunchLog.Printf("While running fusermount: %v", umnterr)
607 mnterr := <-runner.ArvMountExit
609 runner.CrunchLog.Printf("Arv-mount exit error: %v", mnterr)
613 for _, tmpdir := range runner.CleanupTempDir {
614 rmerr := os.RemoveAll(tmpdir)
616 runner.CrunchLog.Printf("While cleaning up temporary directory %s: %v", tmpdir, rmerr)
621 // CommitLogs posts the collection containing the final container logs.
622 func (runner *ContainerRunner) CommitLogs() error {
623 runner.CrunchLog.Print(runner.finalState)
624 runner.CrunchLog.Close()
626 // Closing CrunchLog above allows it to be committed to Keep at this
627 // point, but re-open crunch log with ArvClient in case there are any
628 // other further (such as failing to write the log to Keep!) while
630 runner.CrunchLog = NewThrottledLogger(&ArvLogWriter{runner.ArvClient, runner.Container.UUID,
633 if runner.LogsPDH != nil {
634 // If we have already assigned something to LogsPDH,
635 // we must be closing the re-opened log, which won't
636 // end up getting attached to the container record and
637 // therefore doesn't need to be saved as a collection
638 // -- it exists only to send logs to other channels.
642 mt, err := runner.LogCollection.ManifestText()
644 return fmt.Errorf("While creating log manifest: %v", err)
647 var response arvados.Collection
648 err = runner.ArvClient.Create("collections",
650 "collection": arvadosclient.Dict{
651 "name": "logs for " + runner.Container.UUID,
652 "manifest_text": mt}},
655 return fmt.Errorf("While creating log collection: %v", err)
658 runner.LogsPDH = &response.PortableDataHash
663 // UpdateContainerRunning updates the container state to "Running"
664 func (runner *ContainerRunner) UpdateContainerRunning() error {
665 runner.CancelLock.Lock()
666 defer runner.CancelLock.Unlock()
667 if runner.Cancelled {
670 return runner.ArvClient.Update("containers", runner.Container.UUID,
671 arvadosclient.Dict{"container": arvadosclient.Dict{"state": "Running"}}, nil)
674 // ContainerToken returns the api_token the container (and any
675 // arv-mount processes) are allowed to use.
676 func (runner *ContainerRunner) ContainerToken() (string, error) {
677 if runner.token != "" {
678 return runner.token, nil
681 var auth arvados.APIClientAuthorization
682 err := runner.ArvClient.Call("GET", "containers", runner.Container.UUID, "auth", nil, &auth)
686 runner.token = auth.APIToken
687 return runner.token, nil
690 // UpdateContainerComplete updates the container record state on API
691 // server to "Complete" or "Cancelled"
692 func (runner *ContainerRunner) UpdateContainerFinal() error {
693 update := arvadosclient.Dict{}
694 update["state"] = runner.finalState
695 if runner.finalState == "Complete" {
696 if runner.LogsPDH != nil {
697 update["log"] = *runner.LogsPDH
699 if runner.ExitCode != nil {
700 update["exit_code"] = *runner.ExitCode
702 if runner.OutputPDH != nil {
703 update["output"] = *runner.OutputPDH
706 return runner.ArvClient.Update("containers", runner.Container.UUID, arvadosclient.Dict{"container": update}, nil)
709 // IsCancelled returns the value of Cancelled, with goroutine safety.
710 func (runner *ContainerRunner) IsCancelled() bool {
711 runner.CancelLock.Lock()
712 defer runner.CancelLock.Unlock()
713 return runner.Cancelled
716 // NewArvLogWriter creates an ArvLogWriter
717 func (runner *ContainerRunner) NewArvLogWriter(name string) io.WriteCloser {
718 return &ArvLogWriter{runner.ArvClient, runner.Container.UUID, name, runner.LogCollection.Open(name + ".txt")}
721 // Run the full container lifecycle.
722 func (runner *ContainerRunner) Run() (err error) {
723 runner.CrunchLog.Printf("Executing container '%s'", runner.Container.UUID)
725 hostname, hosterr := os.Hostname()
727 runner.CrunchLog.Printf("Error getting hostname '%v'", hosterr)
729 runner.CrunchLog.Printf("Executing on host '%s'", hostname)
732 // Clean up temporary directories _after_ finalizing
733 // everything (if we've made any by then)
734 defer runner.CleanupDirs()
736 runner.finalState = "Queued"
739 // checkErr prints e (unless it's nil) and sets err to
740 // e (unless err is already non-nil). Thus, if err
741 // hasn't already been assigned when Run() returns,
742 // this cleanup func will cause Run() to return the
743 // first non-nil error that is passed to checkErr().
744 checkErr := func(e error) {
748 runner.CrunchLog.Print(e)
754 // Log the error encountered in Run(), if any
757 if runner.finalState == "Queued" {
758 runner.UpdateContainerFinal()
762 if runner.IsCancelled() {
763 runner.finalState = "Cancelled"
764 // but don't return yet -- we still want to
765 // capture partial output and write logs
768 checkErr(runner.CaptureOutput())
769 checkErr(runner.CommitLogs())
770 checkErr(runner.UpdateContainerFinal())
772 // The real log is already closed, but then we opened
773 // a new one in case we needed to log anything while
775 runner.CrunchLog.Close()
778 err = runner.ArvClient.Get("containers", runner.Container.UUID, nil, &runner.Container)
780 err = fmt.Errorf("While getting container record: %v", err)
784 // setup signal handling
785 runner.SetupSignals()
787 // check for and/or load image
788 err = runner.LoadImage()
790 err = fmt.Errorf("While loading container image: %v", err)
794 // set up FUSE mount and binds
795 err = runner.SetupMounts()
797 err = fmt.Errorf("While setting up mounts: %v", err)
801 err = runner.CreateContainer()
806 runner.StartCrunchstat()
808 if runner.IsCancelled() {
812 err = runner.UpdateContainerRunning()
816 runner.finalState = "Cancelled"
818 err = runner.StartContainer()
823 err = runner.WaitFinish()
825 runner.finalState = "Complete"
830 // NewContainerRunner creates a new container runner.
831 func NewContainerRunner(api IArvadosClient,
833 docker ThinDockerClient,
834 containerUUID string) *ContainerRunner {
836 cr := &ContainerRunner{ArvClient: api, Kc: kc, Docker: docker}
837 cr.NewLogWriter = cr.NewArvLogWriter
838 cr.RunArvMount = cr.ArvMountCmd
839 cr.MkTempDir = ioutil.TempDir
840 cr.LogCollection = &CollectionWriter{kc, nil, sync.Mutex{}}
841 cr.Container.UUID = containerUUID
842 cr.CrunchLog = NewThrottledLogger(cr.NewLogWriter("crunch-run"))
843 cr.CrunchLog.Immediate = log.New(os.Stderr, containerUUID+" ", 0)
848 statInterval := flag.Duration("crunchstat-interval", 10*time.Second, "sampling period for periodic resource usage reporting")
849 cgroupRoot := flag.String("cgroup-root", "/sys/fs/cgroup", "path to sysfs cgroup tree")
850 cgroupParent := flag.String("cgroup-parent", "docker", "name of container's parent cgroup")
853 containerId := flag.Arg(0)
855 api, err := arvadosclient.MakeArvadosClient()
857 log.Fatalf("%s: %v", containerId, err)
861 var kc *keepclient.KeepClient
862 kc, err = keepclient.MakeKeepClient(&api)
864 log.Fatalf("%s: %v", containerId, err)
868 var docker *dockerclient.DockerClient
869 docker, err = dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)
871 log.Fatalf("%s: %v", containerId, err)
874 cr := NewContainerRunner(api, kc, docker, containerId)
875 cr.statInterval = *statInterval
876 cr.cgroupRoot = *cgroupRoot
877 cr.cgroupParent = *cgroupParent
881 log.Fatalf("%s: %v", containerId, err)