LinuxCommandLibrary

systemctl-preset

Apply systemd unit enablement presets

TLDR

Reset the enablement state to preset defaults

$ systemctl preset [unit1 unit2 ...]
copy

Enable only if marked as enabled in the preset policy
$ systemctl preset [unit] --preset-mode enable-only
copy

Disable only if marked as disabled in the preset policy
$ systemctl preset [unit] --preset-mode disable-only
copy

Suppress output and return only the exit code
$ systemctl preset [unit] [[-q|--quiet]]
copy

SYNOPSIS

systemctl-preset [OPTIONS...] [PRESETS...]

PARAMETERS

--dry-run
    Show what actions would be performed without actually making any changes to the system.

--root=PATH
    Operate on a specified alternative root directory PATH instead of the host's root. Useful for chroot or container environments.

--system
    Connect to the systemd system manager instance. This is the default behavior if no other manager is specified.

--user
    Connect to the systemd user manager instance for the current user.

--runtime
    Apply changes only to the runtime configuration, meaning they will not persist across reboots. This affects /run/systemd/system/.

--global
    When used with --user, this applies preset policies globally for all users, not just the current one. It usually affects /etc/systemd/user-preset/.

--no-reload
    Do not reload the systemd manager configuration after applying preset changes. This might leave the manager with an outdated view of unit states.

--no-ask-password
    Do not prompt for passwords. This can be useful in automated scripts where interactive password input is not possible.

-q, --quiet
    Suppress most output from the command, only showing critical errors.

PRESETS...
    One or more specific preset policy files to apply (e.g., 90-default.preset). If omitted, all applicable preset files found in the configured directories will be used.

DESCRIPTION

The systemctl-preset command is a utility within the systemd ecosystem designed to apply 'preset' properties to systemd units. Presets are configuration files that define the default enabled or disabled state for various systemd units (services, sockets, timers, etc.) upon their installation or system setup. This command is frequently invoked by package managers after installing new software packages or by system administrators to enforce a standardized initial configuration for services.

It operates by reading preset files from a defined hierarchy of directories, such as /etc/systemd/system-preset/, /run/systemd/system-preset/, and /usr/lib/systemd/system-preset/. The command evaluates these files, applying their rules to enable, disable, or 'try-enable' units accordingly. Essentially, systemctl-preset acts as an automated front-end to systemctl enable or systemctl disable, driven by the logic specified in the preset files, ensuring consistency in the initial state of services across different installations or system reconfigurations.

CAVEATS

systemctl-preset only manages the enabled/disabled state of units; it does not start, stop, or restart services directly. Its functionality is entirely dependent on the content and correctness of the preset files; misconfigured files can lead to unintended service states. The order of preset files is crucial, as files processed later (lexicographically) can override settings from earlier files. Manual changes to unit states (via systemctl enable/disable) can be overridden by systemctl-preset if it is run again, unless specific preset files exclude those units.

PRESET FILES LOCATION

Preset files are searched for in a specific order of directories, with later directories overriding earlier ones:

  • /etc/systemd/system-preset/
  • /run/systemd/system-preset/
  • /usr/local/lib/systemd/system-preset/
  • /usr/lib/systemd/system-preset/

For user presets, similar paths under ~/.config/systemd/user-preset/, ~/.local/share/systemd/user-preset/, etc., are used.

PRESET FILE FORMAT

Preset files are simple plain text files, typically named with a numerical prefix (e.g., 10-default.preset). Each line in a preset file specifies an action and a unit or unit pattern:

  • enable unit_name.service
  • disable unit_name.service
  • try-enable unit_name.service (enables if no previous preset disabled it)
  • skip unit_name.service (ignores the unit for subsequent presets)

Wildcards (e.g., *.service) can be used to apply actions to multiple units. Comments start with #.

HISTORY

The systemctl-preset command is an integral part of the systemd init system, which was first introduced as a replacement for the traditional SysVinit daemon. It was developed to streamline and standardize the management of service states during operating system installation, package upgrades, and system provisioning. Its introduction reflects systemd's broader goal of providing a more unified and robust system management framework. The concept of presets allows distributors and system administrators to define consistent default behaviors for services, reducing manual configuration effort and improving system predictability. It has evolved alongside the systemd project, continuously integrating with new systemd features and conventions.

SEE ALSO

systemctl(1), systemd.preset(5), systemd(1), systemd.unit(5), systemd.overall(7)

Copied to clipboard