0

Consider the following test-echo.service:

[Unit]
Description=Testing journalling of stdout

[Service]
ExecStart=/bin/echo hello world

[Install]
WantedBy=multi-user.target

Its stdout ends up in the journal as expected:

$ sudo systemctl enable test-echo
$ sudo systemctl start test-echo
$ sudo journalctl -e -u test-echo
> ... systemd[1]: Started Testing journalling of stdout.
> ... echo[20178]: hello world
$ sudo systemctl stop test-echo

Now I add User=ubuntu under the [Service] section. ubuntu is an existing regular user.

$ sudo systemctl daemon-reload
$ sudo systemctl start test-echo
$ sudo journalctl -e -u test-echo
> ... systemd[1]: Started Testing journalling of stdout.

Note that the echo message is now missing from the journal. Why is this, and how can I get it to show up?

I am using systemd 229 on Ubuntu 16.04.

Ruud
  • 135
  • 7

1 Answers1

2

journald is currently unable to attribute the output of processes shortly before they exit, which is especially the case for very short lived processes like echo. This is caused due to how journald acquires certain information (e.g. the _SYSTEMD_UNIT and _COMM fields) from the process' /proc, which might not exist anymore at the point your output is processed.

You can find the bug report on GitHub as well as on the Bugzilla.

  • So a `sleep 1` right after the `echo` would band-aid this? – chicks Dec 18 '16 at 12:52
  • 1
    @chicks In my experience and as far as I understand it: Yes. You can see it in the GitHub issue description how he added a (quite short) `sleep 0.1` after the first `echo before sleep`, which was enough to allow him to see it in the logs. – Leonard Hecker Dec 19 '16 at 14:39