Here is my amazing service, written in shell script:
$ cat ~/junk/demoapp
#! /bin/bash -eu
while true
do
echo "in shell"
( echo "in subshell" )
/usr/bin/echo "in subprocess"
sleep 1
done
It produces some repetitive output:
$ ~/junk/demoapp
in shell
in subshell
in subprocess
in shell
in subshell
in subprocess
in shell
in subshell
in subprocess
in shell
in subshell
in subprocess
^C
Here is a user service configuration for it:
$ cat ~/.config/systemd/user/demoapp.service
[Unit]
Description=Demo App
[Service]
Type=exec
ExecStart=/home/tomanderson/junk/demoapp
But when i run this service, using systemd 239, the logged output is missing the lines produced by the subshell and the subprocess:
$ systemctl --user daemon-reload
$ systemctl --user start demoapp
$ journalctl --user --unit demoapp
Sep 12 18:53:27 myhost systemd[539847]: Started Demo App.
Sep 12 18:53:27 myhost demoapp[559387]: in shell
Sep 12 18:53:28 myhost demoapp[559387]: in shell
Sep 12 18:53:29 myhost demoapp[559387]: in shell
Sep 12 18:53:30 myhost demoapp[559387]: in shell
Sep 12 18:53:31 myhost demoapp[559387]: in shell
Sep 12 18:53:32 myhost demoapp[559387]: in shell
Sep 12 18:53:33 myhost demoapp[559387]: in shell
Sep 12 18:53:34 myhost demoapp[559387]: in shell
Sep 12 18:53:35 myhost demoapp[559387]: in shell
Any idea why? From reading around, it seems that systemd would normally capture output from subprocesses here. Is this something specific that the shell is doing which is interacting with this?
Googling around, i see people having problems like this with Python, where buffering is the culprit, but i don't see how that can be relevant here.
EDIT: I see exactly the same behaviour after taking shell script out of the equation, using two simple C programs. I do not see this behaviour with a simple parent process taking the place of systemd and collecting output via a pipe. This strongly indicates that it is systemd that is doing something funky. See: https://github.com/tomwhoiscontrary/child-stdout-demo
EDIT 2: An observant colleague who has root reports that (a) the subprocess output is in the journal, it's just not associated with the service, and (b) he only sees this behaviour with a user service; if he sets up a system service with the same code, the subprocess output is associated with it! Surely this is a systemd bug?