systemd: journal listing on /dev/tty12
Inspired by the Debian CTTE deliberations on the new default init for Debian, I installed systemd on my notebook after tonight’s forced reboot and played with it a little.
(And I like it! I was very sceptical when hearing about systemd first, but after reading a lot of discussions and trying it myself, I find most of the problematic points either fixed already or a load of FUD. The immediate big selling point for me is actually journald, it and its integration with systemctl is really awesome. I’ll actually find systemd more useful on servers than desktops, I think.)
While it’s a nice exercise for anyone wanting to get familiar with systemd, I still decided to share a tidbit – service file that will make log entries show up on /dev/tty12. Many people run with rsyslogd set up for this, you’ll want to disable that (by default, all journal entries are forwarded to rsyslog). The advantage of showing journal entries instead is mainly color coding. :)
The file listing follows, or get it here.
# Simple systemd service that will show journal contents on /dev/tty12 # by running journalctl -af on it. # Install by: # - Saving this as /etc/systemd/system/journal@tty12.service # - Running systemctl enable journal@tty12 # - Running systemctl start journal@tty12 # journald can also log on console itself, but current Debian version won't # show timestamps and color-coding. # systemd is under LGPL2.1 etc, this is inspired by getty@.service. [Unit] Description=Journal tail on %I Documentation=man:journalctl(1) After=systemd-user-sessions.service plymouth-quit-wait.service systemd-journald.service After=rc-local.service # On systems without virtual consoles, don't start any getty. (Note # that serial gettys are covered by serial-getty@.service, not this # unit ConditionPathExists=/dev/tty0 [Service] # the VT is cleared by TTYVTDisallocate ExecStart=/bin/sh -c "exec /bin/journalctl -af > /dev/%I 2> /dev/%I" Type=idle Restart=always RestartSec=1 UtmpIdentifier=%I TTYPath=/dev/%I TTYReset=yes TTYVHangup=yes #TTYVTDisallocate=yes TTYVTDisallocate=no KillMode=process IgnoreSIGPIPE=no # Unset locale for the console getty since the console has problems # displaying some internationalized messages. Environment=LANG= LANGUAGE= LC_CTYPE= LC_NUMERIC= LC_TIME= LC_COLLATE= LC_MONETARY= LC_MESSAGES= LC_PAPER= LC_NAME= LC_ADDRESS= LC_TELEPHONE= LC_MEASUREMENT= LC_IDENTIFICATION= [Install] Alias=getty.target.wants/journal@tty12.service
(P.S.: Creating this service file – my very first one – took me 10 minutes total, including studying documentation and debugging two stupid mistakes I made.)
Edit (2019-10-19):Â New versions of journalctl check their stderr to decide whether to use colorize output – I have updated the recipe accordingly.
Well, alternatively you can set ForwardToConsole=yes and TTYPath=/dev/tty12 in journald.conf.
@waldi
Indeed, but that (i) will not give me colors, apparently; and more importantly, (ii) it will not print timestamps.
It appears that at least timestamp support already got included upstream, but current systemd in Debian doesn’t print them.
I believe you can directly specify a stdout for the service:
ExecStart=/bin/journalctl -af
StandardOutput=tty-force
TTYPath=/dev/%I
See the description about the various tty options here:
http://www.freedesktop.org/software/systemd/man/systemd.exec.html
Also, the After= lines might not be necessary.
Thank you, this works way better than “ForwardToConsole=yes and TTYPath=/dev/tty12”.
Surprised such functionality isn’t default as it’s very useful.
Shouldn’t StandardOutput be tty only? As one can check at http://www.freedesktop.org/software/systemd/man/systemd.exec.html tty-force is valid for StandardInput only.