systemd-ac-power
Check AC power connection status
TLDR
Silently check and return a 0 status code when running on AC power, and a non-zero code otherwise
Additionally print yes or no to stdout
SYNOPSIS
As a systemd target, ac-power.target does not have a traditional command-line synopsis with options and arguments. It represents a state that the system enters. Its status can be observed or its dependencies managed using the systemctl(1) command, for example:
systemctl status ac-power.target
systemctl list-dependencies ac-power.target
PARAMETERS
N/A
ac-power.target is a systemd target unit and does not accept command-line parameters or options in the manner of a traditional executable program. Its state is determined by the system's hardware detection capabilities, primarily managed by systemd-logind.
DESCRIPTION
ac-power.target is a special systemd target unit designed to signal when the system is connected to an alternating current (AC) power source. It is not an executable command that you run directly from the terminal with arguments. Instead, it represents a specific power state of the system.
This target is automatically activated by systemd-logind(8) when it detects that the machine is operating on AC power. Its primary purpose is to provide a standardized, abstract mechanism for other systemd units, services, or scripts to react to the presence of AC power. For instance, a service might be configured to only run or operate at full performance when ac-power.target is active, thus preventing excessive battery drain. It simplifies power management by allowing developers to express dependencies on the power source rather than directly polling hardware interfaces.
CAVEATS
It is crucial to understand that ac-power.target is not an executable command. It is a conceptual systemd target unit. Its activation and deactivation are managed internally by systemd-logind based on hardware power supply events. Its functionality relies entirely on systemd-logind being active and correctly detecting the power source. There might be a slight delay between a physical power source change and the target's state update due to event processing.
PURPOSE AND ACTIVATION
ac-power.target serves as a vital component for power-aware applications and services. When systemd-logind detects that the system is plugged into an AC power source, it activates this target. Conversely, when AC power is disconnected and the system runs on battery, this target is deactivated. Services can declare a dependency on ac-power.target (e.g., using Wants= or Requires= in their unit files) to ensure they only run or modify their behavior when AC power is available. This is particularly useful for tasks that consume significant power, such as background indexing, software updates, or high-performance computing tasks.
DISTINCTION FROM COMMANDS AND SERVICES
The name 'systemd-ac-power' might lead to confusion, suggesting an executable command. However, it's essential to differentiate between systemd targets (like ac-power.target) and actual executable commands or template services (e.g., systemd-ac-power@.service which might exist in some contexts to perform actions based on this target). ac-power.target itself is purely a state indicator, a logical 'flag' that other systemd units can check or depend upon, rather than a program that performs an action when invoked.
HISTORY
ac-power.target was introduced as part of the broader systemd initiative to unify and streamline system management, including power management. Prior to this, managing power-aware behaviors often involved custom scripts polling /sys files or relying on desktop environment-specific mechanisms. Its inclusion provides a consistent and declarative way for services and applications to integrate with the system's power state, reducing complexity and improving reliability.
SEE ALSO
systemd.special(7), systemd-logind(8), systemctl(1), suspend.target(7), power-supply(4)