Autostart programs on consoles

Hi all, after i gave this advice:

It occurred to me that it would be very handy to automate this, so they start aromatically at system boots using a service unit.
But, i never tried starting stuff on specific consoles using systemd and neither know how to select the console it will be run on.

I remember vaguely in past where we used init.rd configs or something to pull that off, but my memories have faded on that far past.

Anyone any ideas?

Should i be using getty@.service instance overrides maybe?:thinking:

Can you clearly explain what you want to autostart?

You might not need systemd unit files if you just want to run the script as user. You can create a script and then add it to autostart in system settings as you are in KDE

You will need systemd unit file if you want to run something as root user. In order to do that look into https://askubuntu.com/a/960333

in my pc, i have 2 examples for tty :

for tty12
/etc/systemd/system/journal@tty12.service

[Unit]
Description=Journal systemd on %I
Documentation=man:journalctl(1)
After=systemd-user-sessions.service systemd-journald.service
ConditionPathExists=/dev/tty0

[Service]
ExecStart=/usr/bin/sh -c "exec /usr/bin/journalctl -af -p4 > /dev/%I"
Type=idle
Restart=always
RestartSec=1
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=no
KillMode=process
IgnoreSIGPIPE=no

# Unset locale for the console getty since the console has problems
# displaying some internationalized messages.
Environment=LANG=fr LANGUAGE=fr 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

other
/etc/systemd/system/journal@tty6.service

[Unit]
Description=Pacman logs on %I
After=systemd-user-sessions.service systemd-journald.service
ConditionPathExists=/dev/tty0

[Service]
ExecStart=/usr/bin/sh -c "exec /usr/bin/tail -qf /var/log/pacman.log > /dev/%I"
Type=idle
Restart=always
RestartSec=1
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=no
KillMode=process
IgnoreSIGPIPE=no

[Install]
Alias=getty.target.wants/journal@tty6.service
1 Like

I want as example refering to that suggestion i linked to:

  • Run 2 programs on different consoles outside the GUI…
  • On one console, lets say console 12, i want to start htop
  • On the other console, lets say console 11, i want to start journalctl -xf
  • These are prefered to be run as root but that could be controlled in the unit file…

Ohh those look promising, do they autostart at bootup?
(Or better said how to enable them for autostart on boot, just enable --now :thinking: )

Am i right that they’re just the same config as the getty@.service with replaced ExecStart lines?

Going to try nnow hehehe :+1:

I’ve had this unit for years, don’t remember the source (not me), seems like it came from a blog.

journalctl enable to activate and will create a link in /etc/systemd/system/getty.target.wants/
Yes, it’s very similar to getty@.service
The tty is read-only

1 Like

Edit: Tutorial moved to:


Thanks i thought so already looking at it :blush:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.