How is possible to immediately stop the bootup process, show some message (quit splash screen) and shutdown machine if a oneshot service fails?

My service starts just one script. If something went wrong, or better said, if a special condition occurs, I'd like to shutdown the machine. So far, I tried to put inside the script a systemctl poweroff. But unfortunately, this call immediately returns and the bootup process is continued normally doing the shutdown more or less parallel. In my case, the login-screen appears for a few seconds until the poweroff is finally done.

Here is my unit-file:

Description=My Fancy Script



I even tried to use FailureAction= but that doesn't work either.

Any ideas how to do this? There must be a "typical" way. For example, if a mountpoint could not be loaded, the system is put into maintenance mode (this ctrl-D thing ;) ) and the bootup is interrupted.

2 Answers 2


There must be a "typical" way. For example, if a mountpoint could not be loaded, the system is put into maintenance mode and the bootup is interrupted.

Yes, there is. And if you look at /usr/lib/systemd/system/local-fs.target you will find that it is



I see a couple options. One is the brutal option, which may be appropriate for a stateless system that can't be corrupted. That is to add the --force option to poweroff

poweroff --force

The docs for it say: "Force immediate halt, power-off, reboot. Do not contact the init system.".

Other services will continue to start in parallel, but the power down should happen faster.

The behavior you are seeing is because systemd is trying to boot your system as fast possible by doing as much as possible as in parallel. This means it moves on to a next task as soon a dependency is fulfilled, not necessarily when a service finishes running.

Since the login screen and other services don't depend on your service running, they are being started in parallel, even as the shutdown sequence has started to run.

You could solve your issue by forcing the boot process to pause and wait for your task to finish before proceeding. First, decide what services should start until your custom service finishes, then add those services or targets to your file with new Before= entries.

You must log in to answer this question.

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