12

Is there a way to get systemd to tell me the rough order in which it will shutdown services when I cleanly shut the whole system down? Since systemd will shut things down in parallel, I appreciate there is no way to know the exact order, but it would still be very helpful to know what constraints systemd will impose on the shutdown sequence, preferably in some kind of visualization which is easy to understand.

The motivation is that for development and debugging of service files, it would be a lot more convenient to get this predicted list in advance, rather than having to do a real shutdown and then boot up again and inspect the logs every time I want to determine what impact a change to a service unit file or some other aspect of systemd's configuration will have on the shutdown order.

I was hoping that something like

systemctl list-dependencies --before shutdown.service

would do the job, but it only emits:

shutdown.service

3 Answers 3

5

Maybe stating the obvious reduces the learning effect, but all I did to get the full list of reverse dependencies for shutdown-target as asked in the original post, was:

systemctl list-dependencies --after shutdown.target

OT: I ran in a problem where the shutdown of a kubernetes system hangs (the machine becomes irresponsive and will not shut down) because the nfs mounts are killed before the actual services have completed shutdown. This question helped me progress.

0
2

The following might help you :

systemctl list-dependencies --before shutdown.target

Regards,

3
  • 3
    Well, thanks for pointing out my stupid mistake that it's shutdown.target not shutdown.service. However this is still not giving me the ordered list I requested, but instead giving me a very short list, or even an empty one on some systems. Feb 7, 2017 at 13:57
  • Systemd is opaque on purpose, unfortunately. For oldschool sysvinit style, one could probably add logging to the startup-files and register the started processes in a file with a timestamp - at the least that is what would come to my mind first.
    – shevy
    Sep 8, 2017 at 14:40
  • 6
    @AdamSpiers @Mohamed Salhi basically, "before" means "starts before". This means the command you want is systemctl list-dependencies --after shutdown.target... at least that will find everything the first command doesn't. It's also confusing because shutdown.target is starting, but all the other units are stopping, and in this case it doesn't matter whether you have a "before" or "after" ordering; the stopping is done before the starting in both cases.
    – sourcejedi
    Aug 29, 2018 at 22:31
1

Shutdown order is usually the reverse of startup order.

That said, daemons are all sent a shutdown signal, and will take varying amounts of time to actually shut down and exit.

Leaving to plain systemd, I don't think it is feasible to usefully predict what services will exit in what sequence. Further, dependencies will control some sequences.

1
  • 2
    Right - I was aware of that, due to the parallelization. However I don't need the exact order - just which orderings are enforced and which things can potentially run in parallel. I'll update my question to clarify this. Also, can you qualify "usually"? When would it not be the reverse? Mar 18, 2016 at 1:02

You must log in to answer this question.

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