I'm currently trying to make a systemd unit as a web server. Currently, my foo.service file looks as follows:

Description=The Foo Web Server



The foo executable automatically logs all HTTP requests to stdout - this is well tested. However, when I view the logs with journalctl -u foo, I only get output like this:

May 06 17:46:57 localhost systemd[1]: Stopping The Foo Web Server...
May 06 17:46:57 localhost systemd[1]: Started Foo Web Server.
May 06 17:46:57 localhost systemd[1]: Starting The Foo Web Server...
May 06 17:47:08 localhost systemd[1]: Stopping The Foo Web Server...
May 06 17:47:08 localhost systemd[1]: Started The Foo Web Server.
May 06 17:47:08 localhost systemd[1]: Starting The Foo Web Server...

Could someone explain why it's not logging all stdout output? I looked briefly at this previous question, but it doesn't help - however it alluded to something along the lines of "...may not work for systems that don't use full systemd" - would this be the case for Ubuntu 15.04? Thank you in advance, any help with this would be much appreciated!

  • 1
    Make sure, your process is not buffering the output. I was having similar problem and it got resolved by disabling output buffering of my python script. As the number of log records produced was not high, it looked like there is no logging, but in fact, it had yet no chance, as all was still gathering in stdout output buffer. – Jan Vlcinsky May 8 '15 at 20:07
  • 1
    Trying to fix this too. I have an impression that systemd does buffering. stdout is line-buffered in UNIX, but systemd does its own thing and buffers a lot more (in order to be fast but useless maybe). – Velkan May 11 '15 at 11:57
  • I had the same problem and buffering with Python's print function was the problem! Since I was using Python 3 I just used something like print('Hello World!', flush=True) and that did the trick! Output started showing up in journalctl. – timbram Sep 14 '17 at 1:40

In fact, buffering in UNIX depends on the context: when stdout is redirected to something interactive like a console - it is usually line-buffered, otherwise it is fully buffered.

Buffering may be changed inside the application using setvbuf library call.

But it can also be done with stdbuf command on launch:

ExecStart=/usr/bin/stdbuf -oL /opt/foo/.cabal-sandbox/bin/foo

(for line-buffered case)

  • This saved my day! Thank you very much. But I'm a bit confused that with ExecStart=/my/foo/program, why the stdout log is not flushed when the service is terminated, but completely disappears instead. – wlnirvana Aug 15 '18 at 5:24

By default on Ubuntu 15.04, systemd journals are only volatile and kept in /run/systemd/journal and are lost at each reboot. To use persistent systemd journal, you need to create the /var/log/journal directory (and restart systemd-journald.service).

So, may be, stdout output is just redirected to syslog and not kept in systemd journal. For that, you may need to use a persistent systemd journal as explained above.

Have you checked /var/log/syslog for your foo log ?

  • I created the /var/log/journal as you mentioned, but I'm not seeing stdout of my systemd service anyway. in the /var/log/syslog I see neither it. – logoff Jul 28 '15 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.