0

I use Java S2I image for a container running in Openshift (on premise). My problem is that the output of the image is page-buffered and oc logs ... does not show me the last logs.

I could probably spin up my docker image that would do stdbuf -oL -e0 java ... but I would prefer to stick to the 'official' image (just adding the jar to /deployments). Is there any way to reduce buffering (use line-buffering instead of page-buffering), or flush the output on demand?

EDIT: It seems that I could update deployment config and pass stdbuf in there, but that means that I'd have to compose all the args myself. Ideal solution would be passing --tty do Docker, but I can't see how a custom arguments could be passed that way in Openshift.

Radim Vansa
  • 5,686
  • 2
  • 25
  • 40

1 Answers1

0

In your repo, try creating the file .s2i/bin/run. In it add:

#/bin/bash

exec stdbuf -oL -e0 /usr/local/s2i/run

I always forget where the S2I assemble and run scripts are in the Java S2I image, so you may need to replace /usr/local/s2i with the correct path.

What adding this file does is that it will be run as the startup command instead of the original run script. You can then run the original script with stdbuf. Ensure you use exec so that the sub process replaces the current one, else signals will not be propagated through properly.

Even though this might work, am surprised logging isn't working in an unbuffered mode already. I expect there would be a better way of controlling it through some Java config instead.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • I'd expect the same but didn't find it. As per .s2i/bin/run, I use multi-build image where the one buildconfig prepares the JAR file but then in another build I just copy the JAR from builder image to the s2i image. – Radim Vansa May 28 '18 at 16:23