LinuxCommandLibrary

systemctl-condstop

Conditionally stop running services

TLDR

View documentation for the original command

$ tldr systemctl stop
copy

SYNOPSIS

systemctl-condstop [UNIT...]

PARAMETERS

UNIT...
    One or more systemd unit names (e.g., service, socket, device) to be conditionally stopped.

DESCRIPTION

systemctl-condstop is a utility script designed to stop one or more systemd units only if they are currently active or running. Unlike a direct call to systemctl stop, which might fail or issue warnings if a unit is already stopped, systemctl-condstop first checks the unit's status. If the unit is found to be active, it then proceeds to stop it. This conditional stopping prevents unnecessary operations and error messages, making scripts more robust. It is often used in shutdown sequences, dracut environments, or other scenarios where services should only be stopped if they were previously started, ensuring a clean and graceful system termination or transition.

CAVEATS

This command is typically a shell script wrapper, not a built-in systemctl subcommand. Its exact implementation and available options might vary across Linux distributions or even different versions of the same distribution. It relies on the correct functioning of systemctl is-active and systemctl stop. It may not be present on all systemd-based systems by default, often being part of specific packages like dracut.

TYPICAL LOCATION

On many systems, particularly those using dracut, the systemctl-condstop script can be found in paths like /usr/lib/dracut/modules.d/90systemd/systemctl-condstop or similar directories within the dracut module structure. Its presence usually signifies its integration into the early boot or late shutdown phases managed by dracut.

PURPOSE IN SHUTDOWN

During system shutdown or reboot, it's crucial to stop services in an orderly fashion. systemctl-condstop is often employed in these critical phases to ensure that services are only commanded to stop if they were actually running, thus preventing potential race conditions, unnecessary log messages, or delays that could arise from attempting to stop already inactive units.

HISTORY

The systemctl-condstop utility likely emerged with the widespread adoption of systemd as the init system, particularly in contexts requiring robust and error-tolerant service management during system shutdown or reboots. It addresses the common scripting challenge of idempotency: ensuring an operation can be safely repeated without causing errors if the target state is already met. Its primary usage is often seen within initramfs generation tools like dracut, where it plays a role in gracefully stopping services before the root filesystem is unmounted.

SEE ALSO

systemctl(1), systemd.unit(5), dracut(8)

Copied to clipboard