LinuxCommandLibrary

systemctl-add-wants

Add unit's weak dependency

TLDR

Add a Wants dependency from a target to a unit

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

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

Add a user-level Wants dependency
$ systemctl add-wants [target] [unit] --user
copy

SYNOPSIS

systemctl-add-wants [OPTIONS] TARGET_UNIT UNIT_TO_WANT...

PARAMETERS

TARGET_UNIT
    The systemd unit (e.g., a target like `multi-user.target` or a service) that will express the 'Wants=' dependency. This unit will attempt to start the units specified by `UNIT_TO_WANT`.

UNIT_TO_WANT...
    One or more systemd units (e.g., `my-service.service`, `another.target`) that the `TARGET_UNIT` should 'want' to start. These units will be linked into the `TARGET_UNIT`.wants/ directory.

--runtime
    Create the 'wants' symlink in the volatile `/run/systemd/system/` directory. This makes the dependency effective only for the current boot and will be lost after a reboot.

--force
    Overwrite existing symlinks if they point to a different unit or if the target directory already contains a file with the same name. Use with caution to avoid unexpected behavior.

--dry-run
    Show what actions would be performed (e.g., which symlinks would be created) without actually modifying the filesystem. Useful for testing and verifying commands.

DESCRIPTION

The command `systemctl-add-wants` is not a standard utility provided by the `systemd` project itself. Instead, it represents a conceptual operation or a common helper script's function aimed at managing 'Wants' dependencies for systemd units. In `systemd`, a 'Wants=' dependency is a weak dependency: if unit A 'wants' unit B, unit A will attempt to start unit B, but will not fail if unit B cannot be started or if it fails. This is distinct from 'Requires=', which mandates successful startup and continuous operation of the dependency.

Typically, 'Wants' dependencies are established either by adding a `Wants=` directive within a unit file's `[Unit]` section, or by creating symbolic links in `.wants/` directories (e.g., `/etc/systemd/system/multi-user.target.wants/`). The standard way to create these symlinks for system-wide targets is using `systemctl enable service-name`, which will create the necessary symlink, usually in `multi-user.target.wants/` or similar, depending on the unit's `[Install]` section.

If `systemctl-add-wants` were a real command, its purpose would be to provide a more direct and simplified way to create these 'wants' symlinks between an arbitrary target unit and one or more service units, effectively making the target unit 'want' the specified services.

CAVEATS

This command is not a standard systemd utility. Its functionality is typically handled by `systemctl enable` or by manually editing unit files and creating symlinks in the appropriate `.wants/` directories (e.g., `/etc/systemd/system/multi-user.target.wants/`).

Directly manipulating `.wants` directories without using `systemctl` can lead to inconsistent system state or unexpected behavior, as `systemctl` handles dependency resolution, unit reloading, and proper path management more robustly. For permanent, custom dependencies, it is generally recommended to declare `Wants=` directives directly within your unit files rather than relying on scripts that bypass `systemctl`'s standard mechanisms.

<I>WANTS=</I> VS. <I>REQUIRES=</I>

The `Wants=` directive defines a weak dependency: the unit will attempt to start the wanted units, but will not fail if they cannot be started or if they fail. This contrasts with `Requires=`, which establishes a strong dependency where the unit will not start if the required unit cannot be started, and will stop if the required unit stops. `Wants=` is generally preferred for optional or non-critical dependencies.

STANDARD DEPENDENCY MANAGEMENT

To establish a 'wants' dependency, the recommended method is to either:
1. Add a `Wants=your-unit.service` line directly to the `[Unit]` section of the unit file that should want another unit (e.g., `multi-user.target`). After editing, run `systemctl daemon-reload` to apply changes.
2. Use `systemctl enable your-unit.service`, which typically creates a symlink in a default target's `.wants/` directory (e.g., `/etc/systemd/system/multi-user.target.wants/`) based on the unit's `[Install]` section. This is the official way to make a unit start automatically with a target.

HISTORY

The concept of 'Wants' dependencies has been a core part of systemd since its inception, providing a mechanism for weak dependencies between units. This allows for flexible service orchestration where certain services are desired but not strictly required for a system or target to function.

While no dedicated `systemctl-add-wants` command exists in standard systemd distributions, the underlying operation of creating symlinks in `.wants/` directories is fundamental to how `systemctl enable` activates units for specific targets. Over time, various system administrators or distribution maintainers might have developed wrapper scripts or helper functions that behave conceptually like `systemctl-add-wants` to simplify the creation of these symlinks for specific use cases.

SEE ALSO

systemctl(1), systemd.unit(5), systemd.target(5)

Copied to clipboard