Centos – Wait for systemd oneshot service to finish

centoscentos7redhatsystemd

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.

Best Answer

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