21

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

[Unit]
Description=The Foo Web Server

[Service]
Type=simple
ExecStart=/opt/foo/.cabal-sandbox/bin/foo

[Install]
WantedBy=multi-user.target

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!

Athan Clark
  • 617
  • 3
  • 6
  • 9

2 Answers2

12

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)

Velkan
  • 3,681
0

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 ?

solsTiCe
  • 9,515