[systemd-devel] Unbuffered stderr for my systemd service?
chaowang at redhat.com
Mon Jul 15 02:56:29 PDT 2013
I have a service (a script) running under systemd and need its stderr to
be output'd immediately, not line buffered. I tried serveral ways but
didn't work out. I hope to get some feedback here :)
Here's my foobar.service:
echo "Here we go"
for i in `seq 1 10`; do
echo -n a >&2
If run `/bin/foobar.sh` directly, I get char 'a' popping up to console
one by one each 0.1 second. And this is what I expect.
But if I run `systemctl restart foobar.service`, a string "aaaaaaaaaa"
altogether pops up after 1 second.
I've got a ugly workaround by redirecting stderr to /dev/console.
However, I lost the systemd journal feature though :(
I look into the systemd.exec(5), it says in the "StandardOutput=" part:
"[..]syslog+console, journal+console and kmsg+console work similarly but
copy the output to the system console as well"
So systemd first write to syslog/journal then copy the output to
console. And it looks like systemd would use line buffering for both
stdout and stderr.
I'm wondering if there's a way to change the output buffer mode to
unbuffered for a systemd service.
If not, should systemd change stderr buffer mode to unbuffered? Like the
most common situations in Linux.
Also I want to mention that with line buffering, it's impossible to
update information in-place (something like calling times of echo -e
"blah\r", later output will override the former one).
Any comments are welcome! Thanks!
More information about the systemd-devel