LinuxCommandLibrary

systemctl

Manage system services

TLDR

Show all running services

$ systemctl status
copy

List failed units
$ systemctl --failed
copy

Start/Stop/Restart/Reload/Show the status a service
$ systemctl [start|stop|restart|reload|status] [unit]
copy

Enable/Disable a unit to be started on bootup
$ systemctl [enable|disable] [unit]
copy

Reload systemd, scan for new or changed units
$ systemctl daemon-reload
copy

Check if a unit is active/enabled/failed
$ systemctl [is-active|is-enabled|is-failed] [unit]
copy

List all service/socket/automount units filtering by running/failed state
$ systemctl list-units [[-t|--type]] [service|socket|automount] --state [failed|running]
copy

Show the contents & absolute path of a unit file or edit it
$ systemctl [cat|edit] [unit]
copy

SYNOPSIS

systemctl [OPTIONS...] {COMMAND} [NAME...]
systemctl [OPTIONS...] {COMMAND} {UNIT...}
systemctl [OPTIONS...] {COMMAND} {--type=TYPE...}
systemctl [OPTIONS...] {COMMAND} {--all | --user | --failed}

PARAMETERS

start <unit>
    Starts one or more specified systemd units immediately.

stop <unit>
    Stops one or more specified systemd units immediately.

restart <unit>
    Restarts one or more specified systemd units.

reload <unit>
    Reloads the configuration of one or more specified systemd units.

enable <unit>
    Enables one or more systemd units to start automatically at boot.

disable <unit>
    Disables one or more systemd units from starting automatically at boot.

status <unit>
    Shows the runtime status of one or more specified systemd units.

is-active <unit>
    Checks if one or more systemd units are currently active.

is-enabled <unit>
    Checks if one or more systemd units are configured to start at boot.

list-units
    Lists all currently active systemd units, filtered by default to show only loaded units.

list-unit-files
    Lists all installed systemd unit files and their enabled/disabled state.

cat <unit>
    Displays the content of the specified systemd unit file.

reboot
    Reboots the entire system.

poweroff
    Shuts down and powers off the system.

suspend
    Suspends the system into a low-power state.

isolate <target>
    Activates a specified systemd target, deactivating all others.

--user
    Operates on the per-user systemd instance instead of the system instance.

--system
    Operates on the system systemd instance (this is the default).

--failed
    Lists only units that are in a 'failed' state.

--type=<type>
    Filters unit output by unit type (e.g., service, socket, mount).

--state=<state>
    Filters unit output by unit state (e.g., active, inactive, failed).

--no-pager
    Prevents output from being piped into a pager like less.

DESCRIPTION

systemctl is the primary command-line utility for controlling the systemd system and service manager. It provides a unified interface to manage various aspects of a systemd-based Linux system. Users can leverage systemctl to inspect and control the systemd runtime, including crucial operations such as starting, stopping, restarting, reloading, enabling, and disabling services. Beyond services, it extends its functionality to manage other systemd unit types like mount points, sockets, timers, devices, and slice units. systemctl also facilitates control over the system's power state, allowing for reboots, shutdowns, and suspension. It offers a comprehensive overview of the system's current state, active units, and their dependencies, making it an indispensable tool for system administrators and users alike. Its introduction marked a significant shift from older init systems like SysVinit and Upstart, consolidating many disparate management tasks into a single, powerful command.

CAVEATS

systemctl is designed exclusively for systems running systemd as their init system; it is incompatible with traditional SysVinit or OpenRC systems.
Many operations, especially those affecting system-wide services or power states, require root (superuser) privileges to execute successfully.
Correct unit file naming (e.g., appending .service, .target) is crucial for proper command functionality.

UNIT FILES

systemctl directly interacts with systemd 'unit files', which are plain text configuration files defining how systemd manages a specific resource or process. These files typically end with suffixes like .service, .socket, .mount, .target, etc., and are usually located in directories such as /etc/systemd/system/ (for custom or overridden units) and /usr/lib/systemd/system/ (for default system units).

TARGETS

Instead of traditional runlevels, systemd employs 'targets'. A target is a special systemd unit that groups other units, defining a desired system state or a set of functionalities. For instance, multi-user.target represents a command-line interface with network services, while graphical.target includes a graphical desktop environment. systemctl can be used to switch between targets (e.g., systemctl isolate graphical.target) or to query and set the default boot target (e.g., systemctl get-default, systemctl set-default).

HISTORY

systemctl is an integral component of the systemd project, which first emerged in 2010 and was initially adopted by Fedora 15 in 2011. Its development aimed to address limitations of traditional init systems like SysVinit, focusing on faster boot times, parallel service startup, and robust dependency management using Linux cgroups. systemctl rapidly gained widespread adoption, becoming the default init system in most major Linux distributions (e.g., Debian, Ubuntu, CentOS, RHEL, Arch Linux), effectively replacing commands like service and chkconfig for service management.

SEE ALSO

systemd(1), journalctl(1), systemd.unit(5), systemd.service(5), systemd.target(5), bootctl(1), init(1)

Copied to clipboard