[systemd-devel] Unbuffered stderr for my systemd service?

Vivek Goyal vgoyal at redhat.com
Mon Jul 15 07:32:40 PDT 2013

On Mon, Jul 15, 2013 at 05:56:29PM +0800, WANG Chao wrote:
> Hi,
> 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:
> --
> [Service]
> Type=oneshot
> ExecStart=-/bin/foobar.sh
> StandardInput=null
> StandardOutput=syslog
> StandardError=syslog+console
> --
> My foobar.sh:
> --
> #!/bin/sh
> echo "Here we go"
> for i in `seq 1 10`; do
>     echo -n a >&2
>     sleep 0.1
> done
> --
> 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).

CCing Lennart.

This is important functionality for us. makeudmpfile utility (utility which 
filters kernel crash dump and shows the progress bar), run in kdump
kernel. For large machines it displays the progress bar in kernel. Right
now all the code runs from initramfs in the context of a service and
we don't get progress messages. Just we get a 100% message at the end.

Right now we bypassed journal by sending everything to /dev/console but
it is a generic question that any serivce displaying some kind of
progress bar, how is it handled with current journal mechanism.


> Any comments are welcome! Thanks!
> WANG Chao

More information about the systemd-devel mailing list