0

I want to run a service with the output on a certain tty on a Ubuntu server, before any login prompt. I've already successfully made a service that runs htop on tty3:

[Unit]
Description=htop on tty3

[Service]
Type=simple
ExecStart=/usr/bin/htop
ExecStop=/bin/kill -HUP ${MAINPID}
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/tty3
Restart=always
RestartSec=2

[Install]
WantedBy=getty.target

And that works mostly fine and as intended, switching to tty3 (alt+f3) brings up htop as expected, and ending the process restarts it instantly. Even stopping and starting/restarting the service from another tty works fine and as intended.

But there is a weird edge case, which is frustrating my efforts for another service somewhat. If I stop the above service, switch to tty3 which gets me a login prompt, switch back to another tty, and start the service again, htop does not come back. I suspect that this is because the normal login/terminal/whatever has now claimed /dev/tty3, so my service is waiting untill it can claim /dev/tty3.

So my question is, how would I clear a specific tty so this service or a service like it can restart, after a regular bash terminal has already claimed it?

1 Answer 1

1

See the "Virtual Terminals" paragraph in: http://0pointer.de/blog/projects/serial-console.html

By default, logind will auto-start getty processes for virtual terminals #1-#6 as you switch to them, according to the template in /lib/systemd/system/[email protected]. The number of auto-started gettys is controlled by two logind settings: NAutoVTs= and ReserveVT=. You could modify these settings away from defaults by either uncommenting and adjusting them in /etc/systemd/logind.conf, or (recommended) by creating a custom drop-in config file at `/etc/systemd/logind.conf.d/*.conf.

Or you could just use a higher TTY number, leaving #1-#6 for gettys, and #7 and #8 for the GUI (with one extra for fast user switching). There's still #9-#12 free for you.

You must log in to answer this question.

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