6

I have a custom systemd service that runs during the first boot.

If the user has no bootsplash I would like to write to the console and give some info on what's going on. Is there a way to do that from my service?

Here's my systemd service:

[Unit]
Description=Prepare operator after installation
[email protected] [email protected] [email protected] [email protected] [email protected] [email protected]
Wants=network-online.target
After=network.target network-online.target
OnFailure=emergency.target
OnFailureJobMode=replace-irreversibly

[Service]
Type=oneshot
ExecStart=/usr/bin/provision-operator

[Install]
WantedBy=multi-user.target
Christoffer Reijer
  • 254
  • 1
  • 4
  • 10
  • selinux-autorelabel.service does this with `StandardInput=tty` [sic], but I don't know how it works if you _do_ have a bootsplash. – sourcejedi Mar 17 '17 at 15:11

2 Answers2

5

In man systemd.directives, you can search for "output" and find that StandardOutput= is documented in in man systemd.exec. There you can find options including journal+console to send output to the systemd Journal and the system console. You might also try kmsg+console. According to the docs kmsg "connects standard output with the kernel log buffer which is accessible via dmesg(1),"

Mark Stosberg
  • 7,420
  • 1
  • 32
  • 42
0

I did it like this. I don't have a login prompt in tty1. So it does not show MOTD out of the box.

[Service]
Type=oneshot
Restart=no
ExecStartPre=/bin/sleep 10
[email protected] 
ExecStart=
ExecStart=-/bin/cat /etc/motd
StandardOutput=tty
TTYPath=/dev/tty1

Where oneshot says: exec only once. Restart=no requirement of oneshot. Not sure why there are two ExecStart and why "-", this was copy and paste. I added After= / ExecStartPre= because the message did not show up, probably screen was cleared by someone else. So it should be after target "login prompt".

Disclaimer: Use this answer as a collection of ideas. I didn't want them to get lost. Do your own research if you have any questions and feel free to contribute your findings.

This was done on Debian stretch w/o X.

JPT
  • 393
  • 2
  • 13