Skip to content

Inspecting Services with systemd-analyze

systemd-analyze is a powerful tool that helps diagnose and troubleshoot issues related to systemd services. It provides various commands to analyze the performance and dependencies of services, as well as to pinpoint issues during the boot process.

systemd-analyze can help you understand how long each service takes to start during boot. This is useful for identifying services that are slowing down the boot process.

  • To get a summary of the boot time:

    Terminal window
    systemd-analyze

    This command shows the overall time taken to boot, including the kernel, initrd, and user space times.

  • To see a detailed breakdown of how long each service took to start:

    Terminal window
    systemd-analyze blame

    This lists all services in order of their startup time, with the slowest services listed first.

  • For a graphical representation of the boot process, use:

    Terminal window
    system-analyze plot > boot-time.svg

    This command generates an SVG file that visually represents the startup times of all services. You can view this file in any web browser.

To troubleshoot issues related to service dependencies, you can visualize the dependency tree of a specific service. To display the dependency tree of a service:

Terminal window
systemd-analyze critical-chain <service_name>.service

This command shows the critical path that affects the startup time of the service, highlighting any dependencies that may delay its startup.

To verify the configuration of a service’s unit file:

Terminal window
systemd-analyze verify <service-name>.service

This command checks the syntax and can help identify configuration issues.

Cyclic dependencies can cause services to fail or hang during boot. systemd-analyze can check for these issues:

To check for any cyclic dependencies:

Terminal window
systemd-analyze verify --man=your-service-name.service

This will warn you about any loops or issues within the unit’s dependency tree.

systemd-analyze can also assess the security of your service’s configuration:

  • To evaluate the overall threat exposure of systemd services, use:

    Terminal window
    systemd-analyze security
  • To evaluate the security of a specific service:

    Terminal window
    systemd-analyze security <service-name>.service

    This command provides a security assessment, scoring the service based on various hardening options and highlighting potential weaknesses.