Linux – way to see the execution tree of systemd

linuxsystemd

What I mean under the question is: is there a way to dump the ordered list (like pstree does for processes) to see how systemd executed the supplied set of units, i.e. the tree after the dependencies were resolved and jobs were queued for the execution? I know that you can do it by analysing systemd state data, but is there a quick way to see such a tree? It would help a lot in failure investigation (e.g. if you see that the boot process was stuck on some unit you would be able to pinpoint the approximate location for your deeper investigation.

Best Answer

systemd-analyze is your friend. For example systemd-analyze critical-chain outputs blocking tree of daemons. Mine for example:

graphical.target @20.211s
└─multi-user.target @20.211s
  └─nginx.service @19.348s +862ms
    └─network.target @19.347s
      └─NetworkManager.service @10.315s +9.031s
        └─basic.target @10.312s
          └─timers.target @10.311s
            └─systemd-tmpfiles-clean.timer @10.311s
              └─sysinit.target @10.295s
                └─systemd-update-utmp.service @10.167s +127ms
                  └─systemd-tmpfiles-setup.service @10.124s +41ms
                    └─local-fs.target @10.097s
                      └─home-entd-Downloads.mount @10.093s +2ms
                        └─home.mount @9.326s +672ms
                          └─systemd-fsck@dev-sda6.service @8.472s +696ms
                            └─dev-sda6.device @8.471s

NetworkManager in example basically holding entire bootup.

If you want to have more detailed view you can render entire execution chain in a svg file. systemd-analyze plot > something.svg outputs entire chain (120+ modules) as progress bars to high-res svg file which show states, that are blocked and another problems.

Finally you have systemd-analyze dot tool which outputs dot file which outputs entire hierarchy: systemd-analyze dot | dot -Tpng -o stuff.png with dot tool you can output it as ps and svg files too.

All of above tools are built-in in systemd-analyze tool which comes by default with systemd in archlinux at least. I think there is some 3rd party projects dealing with it too.