You are not logged in.

#1 2015-06-24 10:57:28

Herodotus
Member
Registered: 2015-06-16
Posts: 24

how to use systemd to configure each console / getty

Hello,

I have an /etc/rc.local with the following lines, which configure my console to be white instead of grey:

for i in $(seq 1 12); do
  TERM=linux setterm --foreground white --bold on -store > /dev/tty$i
done

This works reasonably well but sometimes I think terminals are initialized after it is run, and they appear grey until I restart the service. I wanted to do something more systemd- idiomatic, and I came up with trying to create an override to the getty service:

sudo systemctl edit getty@

[Service]
ExecStart=
ExecStart=-/bin/sh -c "TERM=linux setterm --foreground white --bold on -store > /dev/%I; agetty --noclear %I $TERM"
Type=simple

However, this must contain some mistake, for it causes new logins to simply appear as an empty screen with only the cursor in the upper left. The command "systemctl restart getty@tty2.service" prints nothing but never terminates.

I would appreciate any help with this - either fixing what I've done, or especially providing a solution which is more elegant (such as a service which runs before each getty service, for example). Thank you!

Offline

#2 2015-06-24 11:22:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: how to use systemd to configure each console / getty

I suspect it may be because there is no terminal for setterm to act on.  A much easier approach would just be to replace agetty with fbgetty or qingy which were made specifically for what you are trying to accomplish.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2015-06-25 07:30:20

Herodotus
Member
Registered: 2015-06-16
Posts: 24

Re: how to use systemd to configure each console / getty

Thank you for the reply Trilby. Does agetty create the terminal? If so I could create a custom login program which does the required initialization and pass it to agetty with "--login-program". However, if I do:

$ sudo sh -c "TERM=linux setterm --foreground white --bold on -store > /dev/tty16"
$ sudo sh -c "echo TESTING > /dev/tty16"                                          
$ sudo chvt 16

then I see a white ("bold") TESTING, even though I never used tty16 before. So I think there must be some bug in my use of systemd. Even

$ sudo sh -c "TERM=linux setterm --foreground white --bold on -store > /dev/tty20"
$ sudo sh -c "/sbin/agetty --noclear tty20 linux"
$ sudo chvt 20

produces a white login prompt... I'll debug and report back.

Last edited by Herodotus (2015-06-25 07:30:58)

Offline

#4 2015-06-25 11:53:40

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: how to use systemd to configure each console / getty

What is your end goal?  Must the login be bold white, or just the resulting shell session?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2015-06-26 05:34:06

Herodotus
Member
Registered: 2015-06-16
Posts: 24

Re: how to use systemd to configure each console / getty

Partly I want to learn about the correct way to do things with Systemd. I realize that I could just put setterm in my .zprofile... I also realize that this may not be the most informative Systemd example, since there may be a bit of special-case stuff going on.

I also think that finding an elegant, "canonical" solution to this problem would benefit the community. I imagine that almost everyone uses LCD displays nowadays, where one wants to get the most out of the backlight - having the kernel boot up with half-brightness text is kind of a CRT-era legacy, unless I'm mistaken. Otherwise I'd be more inclined to settle for a hack.

I promised to debug the stuff I posted but didn't get a chance to do that today. Thanks for your interest.

Offline

#6 2015-07-24 20:14:40

Herodotus
Member
Registered: 2015-06-16
Posts: 24

Re: how to use systemd to configure each console / getty

I'm revisiting this problem. I tried creating the following service and enabling it:

/etc/systemd/system/test-getty.service

[Unit]
Description=test of getty
After=getty@tty4.service
PartOf=getty@tty4.service

[Service]
Type=oneshot
ExecStart=/etc/getty-test tty4
# disable timeout logic
TimeoutSec=0
StandardOutput=tty
StandardInput=tty-force
RemainAfterExit=no
TTYPath=/dev/tty4

[Install]
WantedBy=getty@tty4.service

I figured out that "PartOf" makes the specified script run every time getty@.service is restarted (and checked that this is happening). If I change "After" to "Before" (which makes a bit more sense) then I get the same results below. I added TTYPath, StandardInput, StandardOutput to see if they would help, but I think they shouldn't really be necessary.

The file /etc/getty-test contains:

#!/bin/zsh

set -x

TTY=/dev/$1

TERM=linux setterm --foreground red --bold on -store > $TTY < /dev/null

(echo -n "TTY=$TTY  "; date ) >> $0.log

If I run "/etc/getty-test tty4", then "chvt 4", I can press enter and agetty generates a new login prompt which is red. (I've already activated tty4 before doing this)

If I navigate to tty4 and login and logout, then the new agetty which is spawned is red.

If I "sudo systemctl restart getty@tty4; sudo chvt 4" then I see a blank screen, then a red login prompt appears.

However, if I "sudo systemctl restart getty@tty4; sleep 1; sudo chvt 4" then the prompt is grey as usual.

I guess this is all consistent with what Trilby said, "I suspect it may be because there is no terminal for setterm to act on". In the last case, which is the one I care about, my "getty-test" script was run with no terminal to act on.

Offline

#7 2015-07-24 20:57:46

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 749

Re: how to use systemd to configure each console / getty

setterm just produces escape sequences to the standard output, so when redirecting its output to /dev/tty*, the tty has to be already initialized. Starting your service before getty@.service makes no sense, but even when started after, the tty may not be fully initialized yet and agetty might reset its state.

I'm wondering if all this is necessary at all -- agetty displays the /etc/issue file after initializing the terminal, which might be (mis)used for the escape sequences produced by setterm. Normally, /etc/issue ends with the 'reset' escape to reset the foreground color to gray, but you could set the last sequence to anything. The point of setterm is to provide portable and easy-to-use interface, but I guess it's not that important here. See the issue(5) and agetty(8) man pages for details about the supported escape sequences.

Try

TERM=linux setterm --foreground red --bold on --store > /etc/issue

and disable your custom service.

EDIT: an example of a nice ASCII art issue: https://bbs.archlinux.org/viewtopic.php?id=50845

Last edited by lahwaacz (2015-07-24 21:01:54)

Offline

#8 2015-07-25 02:28:44

Herodotus
Member
Registered: 2015-06-16
Posts: 24

Re: how to use systemd to configure each console / getty

Thank you that works great, lahwaacz! There is one more console-related thing I have in /etc/rc.local:

echo 0 > /sys/class/graphics/fbcon/cursor_blink

I guess the tmpfiles.d solution is most appropriate here?

https://bbs.archlinux.org/viewtopic.php?id=147160

On the other hand - if I can apologize first for going off topic a bit - if I need to configure the trackpad

echo -n c | /sys/devices/platform/i8042/serio1/flags

every time my computer wakes up, tmpfiles.d will not work and I need an "After=suspend.target" service to do it... correct?

Thanks again!

Offline

#9 2015-07-25 05:42:25

lahwaacz
Wiki Admin
From: Czech Republic
Registered: 2012-05-29
Posts: 749

Re: how to use systemd to configure each console / getty

I think that /sys/class/graphics/fbcon/cursor_blink defaults to 0 on my system; nevertheless there seem to be alternatives to control the cursor visibility in the console: http://unix.stackexchange.com/questions … m-blinking

As for the trackpad, you might give udev rules a try; otherwise your approach is correct.

Offline

Board footer

Powered by FluxBB