9

I am doing some server provisioning and I need to run a script AFTER installation as it requires the system to be fully functional, include services. So I cannot put it inside the %post section of my kickstart file.

Instead I have created a systemd service which disables itself as the last thing it does.

[Unit]
Description=Prepare the system after installation

[Service]
Type=oneshot
ExecStart=/usr/bin/prepare-system

[Install]
WantedBy=multi-user.target

The problem is that during the first boot, I get to the login prompt and can even login and start using the system, while the "first boot script" is still running.

This gives the Administrator setting up the system the illusion that the system is finished, when it's really not.

I would instead want the service to delay the booting, preferably showing a message like "The system is being prepared, please wait..." and wait there until the script is finished.

Christoffer Reijer
  • 417
  • 1
  • 4
  • 16
  • The login prompt appears before many things have started on the system, such as networking. Startup is much more highly parallel with systemd than was possible before. If you do this, you may introduce lengthy (and possibly unnecessary) delays in startup of unrelated services. Be careful. – Michael Hampton Feb 24 '17 at 21:05

2 Answers2

6

Found the answer here: https://unix.stackexchange.com/questions/216045/systemd-configure-unit-file-so-that-login-screen-is-not-shown-until-service-exi

Just set Before to when the terminal is available:

[Unit]
Description=Prepare the system after installation
Before=getty@tty1.service getty@tty2.service getty@rrt3.service getty@tty4.service getty@tty5.service getty@tty6.service

[Service]
Type=oneshot
ExecStart=/usr/bin/prepare-system

[Install]
WantedBy=multi-user.target
Christoffer Reijer
  • 417
  • 1
  • 4
  • 16
1

Assuming you use GDM as your login manager, add a line with Before=gdm.service in the [Unit] section.

If you don't use gdm, find out which service starts xorg and put that in the Before= line.

This will cause the task to complete before the login manager displays.

Mark Stosberg
  • 3,901
  • 24
  • 28
  • It's a server without X. I tried to set `WantedBy=default.target` instead and add `Before=multi-user.target` but I still get to the login prompt before the script has finished running. – Christoffer Reijer Feb 24 '17 at 18:21