LinuxCommandLibrary

deb-systemd-helper.

Enable/disable systemd services during package installation

SYNOPSIS

deb-systemd-helper [OPTIONS] COMMAND [UNIT_NAME...]

PARAMETERS

--quiet
    Suppresses most standard output messages, useful for maintainer scripts where verbose output is not desired.

--force
    Forces the operation, for instance, enabling a unit even if it's masked or already enabled. The exact behavior depends on the command.

--no-reload
    Prevents deb-systemd-helper from issuing a systemctl daemon-reload command after modifying unit files. This can be useful in scenarios where multiple changes are made and a single daemon-reload is preferred at the end.

DESCRIPTION

deb-systemd-helper is a crucial utility in Debian-based systems, designed to simplify the interaction between Debian package maintainer scripts and systemd service management. Its primary role is to abstract the complexities of enabling, disabling, starting, stopping, masking, or unmasking systemd units during package installation, upgrade, or removal. Maintainer scripts (preinst, postinst, prerm, postrm) use deb-systemd-helper to ensure that services are correctly configured and managed, regardless of whether systemd is the active init system or if a different init system (like SysVinit) is in use.

This helper checks for the presence and readiness of systemd before attempting any systemctl operations, failing gracefully or falling back to update-rc.d for compatibility when systemd is not available or not fully functional. It aims to provide a consistent interface for package maintainers, reducing the burden of writing complex conditional logic to handle various init system environments.

CAVEATS

deb-systemd-helper is primarily intended for use by Debian package maintainer scripts and is not generally meant for direct interactive use by end-users. For direct systemd management, systemctl is the appropriate tool.

It performs checks for systemd's availability and may gracefully do nothing or fall back to update-rc.d for legacy SysVinit compatibility if systemd is not the active init system, ensuring package installations don't fail on non-systemd systems.

While it simplifies maintainer scripts, understanding underlying systemd concepts and systemctl operations is still beneficial for debugging.

COMMON COMMANDS

Here are some of the most common commands used with deb-systemd-helper, typically called within package maintainer scripts:

  • enable UNIT_NAME...:
    Enables one or more systemd units for boot-time start. This typically creates symlinks in multi-user.target.wants or similar directories.
  • disable UNIT_NAME...:
    Disables one or more systemd units, preventing them from starting at boot. Removes the symlinks created by enable.
  • mask UNIT_NAME...:
    Masks one or more systemd units, effectively preventing them from being started manually, automatically, or by other units. This is achieved by linking the unit file to /dev/null.
  • unmask UNIT_NAME...:
    Unmasks one or more systemd units, reversing the effect of mask.
  • restart UNIT_NAME...:
    Restarts one or more systemd units. This is often used during package upgrades if a service needs to be reloaded to pick up new configuration.
  • reload UNIT_NAME...:
    Reloads the configuration of one or more systemd units without restarting the entire service. Not all services support this.
  • try-restart UNIT_NAME...:
    Restarts one or more systemd units only if they are currently running.
  • update-rc.d UNIT_NAME...:
    This command is a fallback for enable/disable on non-systemd systems, effectively passing arguments to the update-rc.d utility for SysVinit compatibility.

USAGE IN MAINTAINER SCRIPTS

deb-systemd-helper is typically invoked in Debian package maintainer scripts (preinst, postinst, prerm, postrm). For example:

  • In postinst, to enable a service after installation:
    deb-systemd-helper enable my-service.service
  • In prerm, to disable a service before removal:
    deb-systemd-helper disable my-service.service
  • In postinst during an upgrade, to restart a service:
    deb-systemd-helper restart my-service.service

HISTORY

deb-systemd-helper emerged as part of Debian's transition to systemd as the default init system. Introduced to ease the migration process for package maintainers, it provided a standardized and robust way to interact with systemd services from within dpkg maintainer scripts. Its development focused on ensuring backward compatibility and graceful degradation on systems not running systemd, thus smoothing the transition across the Debian ecosystem.

SEE ALSO

Copied to clipboard