LinuxCommandLibrary

systemctl-add-requires

Add systemd unit requires dependency

TLDR

Add a Requires dependency from a target to a unit

$ systemctl add-requires [target] [unit]
copy

Add multiple Requires dependencies at once
$ systemctl add-requires [target] [unit1 unit2 ...]
copy

Add a user-level Requires dependency
$ systemctl add-requires [target] [unit] --user
copy

SYNOPSIS

systemctl-add-requires <UNIT_FILE_PATH>...

PARAMETERS

<UNIT_FILE_PATH>
    One or more paths to systemd unit files (e.g., /usr/lib/systemd/system/myunit.service, /etc/systemd/system/anotherservice.socket). The script scans these files to extract dependency information.

DESCRIPTION

systemctl-add-requires is a utility script primarily used within RPM packaging workflows, specifically in conjunction with systemd-rpm-macros. Its main purpose is to automatically parse systemd unit files (e.g., .service, .socket, .timer) and extract their declared dependencies and relationships, such as Requires=, Wants=, Before=, After=, and Conflicts=.

The script then translates these unit relationships into Requires: entries suitable for inclusion in an RPM .spec file. This automation helps ensure that when a package providing systemd units is installed, all necessary systemd units it depends on are also installed, improving system stability and simplifying package maintenance. It is not typically executed directly by end-users for general system administration tasks, but rather invoked during the package build process to generate correct RPM dependencies.

CAVEATS

  • This command is primarily a build-time utility, not intended for runtime system administration. Directly executing it outside of a package build context may not be useful for end-users.
  • It typically outputs Requires: lines to standard output, which are then usually captured and added to an RPM .spec file. It does not modify systemd configurations or unit files directly.
  • Its exact behavior and any available command-line options can vary slightly depending on the specific systemd-rpm-macros package version and distribution it originates from.

INTEGRATION WITH RPM BUILDS

This script is typically invoked within the %build or %prep sections (or similar build phases) of an RPM .spec file, often through systemd-rpm-macros. It helps generate the necessary Requires: entries that ensure dependent systemd units are installed alongside the package providing the main unit. This prevents broken dependencies and ensures the correct functioning of services and applications when installing or removing packages that interact with systemd.

HISTORY

The systemctl-add-requires script emerged as a crucial component during the widespread adoption and integration of systemd into RPM-based distributions like Fedora and RHEL. As systemd became the default init system, packages providing systemd units required a robust and automated mechanism to declare their dependencies on other units. This was essential to ensure a functional and stable system upon installation and upgrade.

Instead of requiring package maintainers to manually inspect each unit file and add complex Requires: lines to .spec files, this utility was developed as a macro-driven solution within systemd-rpm-macros. Its introduction significantly automated this process, making package maintenance more efficient, less error-prone, and tightly coupled with the evolving systemd packaging guidelines.

SEE ALSO

systemctl(1), systemd.unit(5), rpm(8), dnf(8), spec(7)

Copied to clipboard