output held onto when running in Docker #10

Closed
jantman opened this Issue Feb 7, 2017 · 1 comment

Projects

None yet

1 participant

@jantman
Collaborator
jantman commented Feb 7, 2017 edited

We're building backupsss into a docker container like:

FROM ubuntu:latest

RUN apt-get update && apt-get install -y ruby

RUN gem install --no-ri --no-rdoc backupsss -v 0.3.1

(which gives ruby 2.3.1)

And running with (simplified): docker run <container name> backupsss.

However, when the cron timer ticks and the backups run, we see output from everything up to Create and Upload Tar: Starting. The rest of the output (the output of the command itself and the debugging around it from Backupsss::Tar.valid_exit? as well as the upload and cleanup) doesn't show up in the logs until the next run.

Note the change in the hour of the timestamp after the "Create and Upload Tar: Starting" line...

  20170207T120900+0000       /jenkins-master-backupsss  backups/1486242540.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486238940.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486235340.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486231740.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486228140.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486224540.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486220940.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486217340.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486213740.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486210140.tar (retaining)
  20170207T120900+0000       /jenkins-master-backupsss  backups/1486206540.tar
  20170207T120900+0000       /jenkins-master-backupsss  Cleaning up backups/1486206540.tar
  20170207T120900+0000       /jenkins-master-backupsss  Finished cleaning up.
  20170207T120900+0000       /jenkins-master-backupsss  Create and Upload Tar: Starting
  20170207T130900+0000       /jenkins-master-backupsss  command.......tar -zcvf
  20170207T130900+0000       /jenkins-master-backupsss  stderr........tar: Removing leading `/' from member names
  20170207T130900+0000       /jenkins-master-backupsss  tar: Removing leading `/' from hard link targets
  20170207T130900+0000       /jenkins-master-backupsss
  20170207T130900+0000       /jenkins-master-backupsss  status........pid 4000 exit 0
  20170207T130900+0000       /jenkins-master-backupsss  exit code.....0
  20170207T130900+0000       /jenkins-master-backupsss  Checking backup size ...
  20170207T130900+0000       /jenkins-master-backupsss  Size of backup is greater than 100MB
  20170207T130900+0000       /jenkins-master-backupsss  Creating a multipart upload
  20170207T130900+0000       /jenkins-master-backupsss  Starting multipart upload at 2017-02-07 12:09:32 +0000
  20170207T130900+0000       /jenkins-master-backupsss  Uploading backup as 5 parts
  20170207T130900+0000       /jenkins-master-backupsss  Uploading part number 1 : <upload ID>
... (more uploading)
  20170207T130900+0000       /jenkins-master-backupsss  Completed multipart upload at 2017-02-07 12:09:41 +0000
  20170207T130900+0000       /jenkins-master-backupsss  Completed in 0.16 minutes.
  20170207T130900+0000       /jenkins-master-backupsss  Create and Upload Tar: Finished
  20170207T130900+0000       /jenkins-master-backupsss  Found garbage...
  20170207T130900+0000       /jenkins-master-backupsss  1486469340.tar
  20170207T130900+0000       /jenkins-master-backupsss  Cleaning up 1486469340.tar
  20170207T130900+0000       /jenkins-master-backupsss  Finished cleaning up.

The "Completed in 0.16 minutes" timestamp confirms that this is an output problem.

@jantman
Collaborator
jantman commented Feb 7, 2017

The solution appears to just be adding STDOUT.sync = true somewhere near the entry point of the gem.

See https://gist.github.com/jantman/c8081c027e711cb3514783133cdd1afb as an example. With the code as it currently is, output is buffered from the time Open3.capture3 is called until the next time Open3.capture3 is called. Adding STDOUT.sync = true results in the desired behavior of output being flushed as it's written.

@reppard reppard closed this in #11 Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment