systemd generates services logs to the syslog by default (/var/log/messages). Unless logging is explicitly turned off for a specific service, all output written to stderr/stdout of a service goes to syslog. I have created a simple systemd service file for a custom application. The script works well when I run it manually and I am able to get logs on console. But I get the logs in syslog when I run it with systemd/service even when I’m directing them explicitly to the syslog and console.
I’m trying to track down where my problem is, but I don’t know where to find the output (or how to configure systemd to put the output on console).
Here is my service file which is on the path /etc/systemd/system/:
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/init.d/watchdog
Description=SYSV: Control Server watchdog
Before=multi-user.target graphical.target
[Service]
Type=forking
Restart=no
TimeoutSec=5m
RemainAfterExit=no
ExecStart=/etc/init.d/watchdog start
ExecStop=/etc/init.d/watchdog stop
StandardOutput=syslog+console
StandardError=syslog+console
Throughout the application, I output all my logs to stdout and stderr.
my query is “how can I redirect the output of my daemon to the console?”
Note:
If in the Unit file I have used
StandardOutput=tty and
TTYPath=/dev/pts/0
then in this case I get the Output on the Console but In this case we will get the output to the particular terminal which have the tty “/dev/pts/0”.
I have tried given scenarios but none worked for me:
-
Try to /etc/systemd/system.conf file
change: DefaultStandardOutput=syslog+console -
In /etc/systemd/system/watchdog.service
StandardOutput=tty
TTYPath=/dev/tty -
In /etc/systemd/system/watchdog.service
StandardOutput=inherit -
In /etc/systemd/system/watchdog.service
StandardOutput=journal+console -
In /etc/systemd/system/watchdog.service
StandardOutput=fd -
In /etc/systemd/system/watchdog.service
StandardOutput=console -
In /etc/systemd/system/watchdog.service
StandardOutput=tty
TTYPath=/dev/tty0 -
In /etc/systemd/jornald.conf
ForwardToConsole=yes
and restart the service by command - systemctl restart systemd-journald