12

When I run the service manually, it logs something when it starts.

But I cannot find this log anywhere when it starts as systemd process.

journalctl -u <service> only shows the records about the service starting and stopping, not the actual service output.

I tried adding config to /etc/systemd/system/<service>.service file:

StandardOutput=append:/var/opt/<service>/stdout.log
StandardError=append:/var/opt/<service>/stderr.log

but it also didn't help - the files are created after daemon and service restart, but they are empty.

What am I missing?

Thank you for any suggestions, I am out of ideas.

esp
  • 221

2 Answers2

6

Use the following in the unit file

[Service]
StandardError=journal
StandardOutput=journal
StandardInput=null

See here for more: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=

0

I met similar issue. I was writing a program in C. And systemd journalctl does not log my program's printf() stdout. I searched online and from these links https://unix.stackexchange.com/questions/725331#comment1376185_725331 https://stackoverflow.com/a/7876743 https://unix.stackexchange.com/questions/785686#comment1505589_785686 I learned that I need fflush(stdout); after printf() for systemd to log my stdout. Without fflush, fprintf stderr works, printf not work, fprintf stdout not work. Maybe other ways to flush buffers or disable buffering also works.

If the program you want systemd journalctl to log is in C, one way to solve your issue is to edit the program to add fflush(stdout); after printf and fprintf.

xyz
  • 21