The systemctl list-dependencies
command in Linux, using systemd, is a powerful tool for exploring the dependency relationships between various system units.
In systemd, units can have dependencies on each other — for example, one service might require another service to be running, or a target unit might depend on multiple services to function properly. This command allows you to view these dependencies in a tree-like structure, helping you understand how system services and resources are interconnected.
This guide will walk you through how to use the systemctl list-dependencies
command in RHEL, including syntax, common options, and practical examples.
Table of Contents
Syntax
systemctl list-dependencies [UNIT]
- UNIT: The name of the systemd unit for which you want to list dependencies (e.g., a service, target, or socket). If no unit is specified, the command will show the dependencies of the default target (
default.target
).
Key Options:
--reverse
: Shows units that depend on the specified unit (reverse dependencies).--all
: Includes inactive or not loaded units in the output.
Steps to Use systemctl list-dependencies
1. Listing Dependencies of a Service
To view the dependencies of a specific service, use the systemctl list-dependencies
command followed by the name of the service unit. For example, if you want to list the dependencies of the Apache HTTP server (httpd
), you would run:
Get Your Free Linux training!
Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!systemctl list-dependencies httpd.service
This will display a list of units that httpd.service
depends on and other units that are required for httpd.service
to function properly.
Example:
systemctl list-dependencies httpd.service
Output:
httpd.service
● ├─system.slice
● └─network.target
- network.target: This indicates that
httpd.service
depends on the network being available. - system.slice: This is the default slice under which system services run.
2. Listing Dependencies of a Target (Runlevel)
Targets in systemd represent different system states or runlevels. To view the dependencies of a target, such as multi-user.target
(which is a common target for multi-user, non-graphical systems), use:
systemctl list-dependencies multi-user.target
This shows all the services and other targets required for the multi-user
run level to be fully functional.
Example:
systemctl list-dependencies multi-user.target
Output:
multi-user.target
● ├─graphical.target
● ├─basic.target
● ├─sockets.target
● ├─system.slice
● └─network.target
- graphical.target: This is a higher-level target, typically for systems that need a graphical user interface (GUI).
- basic.target: This target is used to initialize basic system components.
- sockets.target: This target is used to start services waiting for socket connections.
- network.target: This indicates that the network is up and ready.
3. Using --reverse
to List Reverse Dependencies
Sometimes, you may want to find out which units depend on a specific unit. To do this, use the --reverse
flag. For example, if you want to find out which services depend on the httpd.service
, run:
systemctl list-dependencies --reverse httpd.service
This will show a list of units that depend on httpd.service
to be running.
Example:
systemctl list-dependencies --reverse httpd.service
Output:
● ├─multi-user.target
● └─graphical.target
This tells you that httpd.service
is required by both multi-user.target
and graphical.target
, meaning that the HTTP service is essential for those targets to function properly.
4. Including All Units (Active and Inactive)
By default, systemctl list-dependencies
only shows units that are active or loaded. To see all units, including inactive ones, use the --all
option. For example:
systemctl list-dependencies --all httpd.service
This will show you not only the active units but also any inactive or non-loaded units that might be part of the dependency tree.
Example:
systemctl list-dependencies --all httpd.service
Output:
httpd.service
● ├─system.slice
● ├─network.target
● ├─some-unloaded-unit.service
This output includes any units that are not loaded or inactive, which might be required under certain conditions.
5. Viewing the Dependencies of the Default Target
If you want to list the dependencies of the system’s default target (the one the system boots into), you can omit the unit name, and it will show the default target’s dependencies. For example:
systemctl list-dependencies
This will display the dependencies for the default target, which is typically either graphical.target
or multi-user.target
depending on your system setup.
Practical Use Cases
1. Troubleshooting Services
When a service isn’t starting or functioning as expected, knowing what it depends on can be helpful. For example, if httpd.service
isn’t starting, you can use systemctl list-dependencies --reverse httpd.service
to find out which other units are waiting for httpd
to start. This can provide insight into what might be blocking the service from starting.
Example:
systemctl list-dependencies --reverse httpd.service
This will tell you which services or targets depend on httpd.service
to be active.
2. Exploring System States
When managing RHEL systems, you might want to know which services will be started when a particular target is reached. For instance, if you are exploring the multi-user.target
, use systemctl list-dependencies multi-user.target
to see which services and targets are involved in the multi-user state.
Example:
systemctl list-dependencies multi-user.target
3. Verifying Services Before Reboot
Before rebooting or switching to a different target, you might want to check if all the necessary dependencies are in place. For example, ensuring that multi-user.target
has all required services before entering multi-user mode can prevent system issues.
systemctl list-dependencies multi-user.target
Conclusion
The systemctl list-dependencies
command is an essential tool for system administrators and power users working with systemd in RHEL (Red Hat Enterprise Linux). It allows you to explore the dependency relationships between different systemd units, whether you’re troubleshooting a service or trying to understand how services are linked together under specific system states.
By mastering this command, you can:
- Troubleshoot service failures by understanding dependencies.
- Explore system state dependencies for specific targets.
- Get a comprehensive view of service and target relationships.
Whether you’re diagnosing issues or simply exploring the inner workings of your RHEL system, systemctl list-dependencies
is a powerful command that enhances your ability to manage and maintain Linux systems effectively.