systemctl-is-active
Check if a systemd unit is active
TLDR
Check whether a unit is active
Check whether multiple units are active
Check whether a unit is active without printing the state to stdout
Check whether a user unit is active
SYNOPSIS
systemctl is-active [OPTIONS...] UNIT...
PARAMETERS
UNIT...
One or more systemd unit names (e.g., apache2.service, multi-user.target) whose active state is to be checked.
--quiet
Suppresses output to standard output, making the command rely solely on its exit code for status determination. Useful for scripting when no console output is desired.
--user
Connects to the systemd user instance for the current user, rather than the system-wide manager. This allows checking units managed by the user's session.
--system
Connects to the system-wide systemd manager instance. This is the default behavior when no specific manager is specified.
--host=HOST
Operates on a remote host identified by HOST. This option is typically used for managing systemd instances over SSH.
--machine=CONTAINER
Operates on a local container identified by CONTAINER. This allows managing systemd instances within specified containers.
DESCRIPTION
The systemctl is-active command is a specialized subcommand of the systemctl utility, which serves as the primary interface for controlling the systemd system and service manager.
Its fundamental purpose is to ascertain the current active state of one or more specified systemd units. The active state indicates whether a unit is actively running, stopped (inactive), in a failed state, or transitioning between states. This command is particularly valuable for scripting and automation, allowing conditional logic to be executed based on a service's operational status.
Upon execution, systemctl is-active returns a specific exit code: 0 if all specified units are active, 1 if at least one unit is not active (e.g., inactive, failed, reloading), and 3 if a unit name is unknown or invalid. By default, it also prints the active state (e.g., "active", "inactive", "failed") to standard output, unless the --quiet option is used. It supports various systemd unit types, including .service, .socket, .timer, .mount, and .target, providing a versatile tool for system administrators and developers.
CAVEATS
The command's output (or lack thereof with --quiet) combined with its exit code is the primary indicator of a unit's active state. An inactive state does not necessarily imply a failed state; an inactive unit might simply be stopped normally. Permissions are crucial; checking system-level units often requires root privileges (e.g., using sudo) if performed by a non-root user.
EXIT CODES
The exit code returned by systemctl is-active is paramount for scripting purposes:
- 0: All specified units are active.
- 1: At least one of the specified units is inactive, failed, reloading, activating, or in another non-active state.
- 3: One or more unit names provided were unknown, invalid, or could not be found by systemd.
UNIT TYPES
systemctl is-active can check the status of various systemd unit types, not just services. Common types include:
- .service: A system service (e.g., web server, database).
- .socket: An IPC socket for systemd-activated services.
- .device: A kernel device.
- .mount: A filesystem mount point.
- .automount: An automount point.
- .swap: A swap device or file.
- .target: A synchronization point or grouping of other units.
- .path: A file system path for path-activated services.
- .timer: A timer for timer-activated services.
HISTORY
The systemctl command, including its is-active subcommand, was introduced as part of the systemd initialization system. systemd began development in 2010 and rapidly gained adoption across major Linux distributions, effectively replacing older init systems like SysVinit and Upstart. The is-active subcommand has been a fundamental component since its inception, providing a consistent and programmatic way to query service states, which is critical for the robust automation and monitoring capabilities offered by the systemd ecosystem.


