8

I am not able to figure out what option to pass in StandardOutput= for a unit file (.service), where I want to show some messages on the connected terminal from where the service is started! (console/tty doesn't seem to be what I want)

Maybe /etc/systemd/system.conf's global default DefaultStandardOutput=journal can be changed, but I don't want to do that! I am only interested in showing some progress/startup messages from my unit file (like systemd-run -P)

I am on Ubuntu 18.04.2

# systemd --version
systemd 237
0

3 Answers 3

1

You can take a look at https://www.freedesktop.org/software/systemd/man/systemd.exec.html#StandardOutput=

If I understand the question correctly you want the service outputs status to tty / console? Remember that when a service is started systemd take care of default file descriptors.

You can use a file to store the status and query it there.

3
  • No, that doesnt work! I already have StandardOutput=file:/path/to/file in all my units
    – Ani
    Mar 3, 2020 at 16:37
  • 1
    you can make it over rsyslog serverfault.com/questions/381353/…
    – nobody
    Mar 7, 2020 at 20:02
  • No, these are debug logs and can be huge in volume. I don't want 20+ of my daemons to all write debug/trace logs via syslog
    – Ani
    Mar 12, 2020 at 8:31
0

Edit your script you want to run using systemd and add | logger to command you want output from to syslog:

#!/bin/bash
/usr/bin/ps aux | /usr/bin/grep gnome > /home/user/test/psoutput.txt
/usr/bin/date | logger
echo "This is terminal output" | logger
/usr/bin/date >> /home/user/test/psoutput.txt

Output of $ sudo journalctl -u pstofile -f is:

бер 09 13:33:42 lenovo systemd[1]: Started ps aux to file.
бер 09 13:33:42 lenovo root[8491]: понеділок, 9 березня 2020 13:33:42 +0200
бер 09 13:33:42 lenovo root[8493]: This is terminal output
бер 09 13:33:42 lenovo systemd[1]: pstofile.service: Succeeded.

My systemd service file contains the next:

[Unit]
Description=ps aux to file
After=systemd-user-sessions.service

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/home/user/test/pstofile.sh
StandardInput=journal+console
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target
0

Its been quite long, I just want to update how I solved this. I created a POSIX MQ, on which a daemon listens on. This daemon is in charge of displaying to the current pty (mq_receive() + write()). All the daemons send a message on the queue when they start, and when they stop (with mq_send())

When I start the main service, I will also start this display service giving it, the pty info.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .