systemctl-condreload
Reload systemd units conditionally
TLDR
View documentation for the original command
SYNOPSIS
systemctl-condreload [OPTIONS] UNIT_NAME...
PARAMETERS
UNIT_NAME...
One or more systemd unit names (e.g., 'nginx.service', 'php-fpm.socket') to check and potentially reload. These are typically required.
--config-files
Specifies a comma-separated list of configuration file paths to monitor for changes for the given unit. If not provided, the script might infer common config paths or rely on internal logic.
--state-file
Defines the path to a file where the script stores the last known modification states (e.g., timestamps or hashes) of the configuration files. Defaults to a location like '/var/lib/systemctl-condreload/
--force
Forces a reload of the specified unit(s) regardless of whether configuration changes were detected.
--dry-run
Performs all checks and indicates which units would be reloaded, but does not actually execute the systemctl reload/restart command.
--verbose
Enables verbose output, showing more details about the checks being performed and the decisions made.
--command
Specifies the systemctl command to execute upon detecting changes. Common choices are 'reload' or 'try-reload-or-restart'. Defaults to 'try-reload-or-restart' for safety.
DESCRIPTION
The command systemctl-condreload is not a standard Linux executable but rather a common name for a utility or script designed to conditionally reload one or more systemd units (services, sockets, etc.) only if their associated configuration files have been modified. This approach aims to minimize service interruptions by avoiding unnecessary reloads when no changes have occurred.
Typically, such a script works by:
- Monitoring specified configuration files for changes, often by comparing their modification timestamps (mtime) or content hashes (e.g., MD5, SHA256) against a previously recorded state.
- If a change is detected in any monitored file for a given unit, it then executes a systemd command such as systemctl reload or the more robust systemctl try-reload-or-restart for that unit. The latter is often preferred as it attempts a reload and falls back to a full restart if reloading is not supported or fails.
The primary benefit of systemctl-condreload is optimizing system stability and performance by preventing superfluous service reloads, which can cause brief downtimes or resource spikes. It is widely used in automated deployment pipelines, configuration management systems (like Ansible, Puppet, Chef), and custom system maintenance scripts.
CAVEATS
As systemctl-condreload is a conceptual or user-defined script, its exact implementation, features, and robustness can vary significantly. Users should verify the script's source and behavior.
It typically relies on file modification times or content hashes, which might not always capture all relevant configuration changes (e.g., if a file is replaced by a symbolic link, or if changes occur outside the monitored paths). Incorrect permissions on state files or configuration directories can also prevent it from working correctly.
TYPICAL IMPLEMENTATION LOGIC
A common implementation of systemctl-condreload involves:
1. Storing the MD5/SHA256 hash of monitored config files in a state file (e.g., `/var/lib/systemctl-condreload/myservice.state`).
2. On subsequent runs, recalculating the hash of the current config files.
3. Comparing the current hash with the stored hash. If they differ, the service is reloaded/restarted, and the new hash is stored. If identical, no action is taken.
INTEGRATION WITH CONFIGURATION MANAGEMENT
Configuration management tools like Ansible often achieve this 'conditional reload' functionality through 'handlers'. An Ansible handler for a service reload is only triggered if a preceding task (e.g., templating a config file) reports a change. This effectively mimics the conditional reload behavior without needing a separate `systemctl-condreload` script for many common scenarios.
HISTORY
The concept behind systemctl-condreload emerged with the need for more intelligent service management in automated environments. While systemd itself provides basic `reload` and `try-reload-or-restart` commands, the conditional logic to *only* perform these actions when necessary was often delegated to external scripts or configuration management tools. This pattern became particularly prevalent in the era of continuous deployment and infrastructure-as-code, where minimizing service disruption during configuration updates is critical. Although not a part of core systemd, such scripts have been a common and practical solution for years.


