Home > linux > systemd: journal listing on /dev/tty12

systemd: journal listing on /dev/tty12

February 12th, 2014 Leave a comment Go to comments

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.

Categories: linux Tags: , ,
  1. waldi
    February 12th, 2014 at 18:04 | #1

    Well, alternatively you can set ForwardToConsole=yes and TTYPath=/dev/tty12 in journald.conf.

  2. pasky
    February 12th, 2014 at 18:35 | #2

    @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.

  3. Marc Schütz
    February 21st, 2014 at 00:29 | #3

    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.

  4. _mb
    August 18th, 2015 at 15:27 | #4

    Thank you, this works way better than “ForwardToConsole=yes and TTYPath=/dev/tty12”.

    Surprised such functionality isn’t default as it’s very useful.

  5. Horst
    December 24th, 2017 at 16:04 | #5

    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.

  1. No trackbacks yet.


6 − five =