Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Packages and Services

Linux systemctl command

Reference for systemctl: start, stop, restart, enable and disable services, check status, list units, mask services and write simple unit files for systemd.

systemctl is the control tool for systemd, the init system and service manager of most modern Linux distributions. It starts and stops services, decides which ones run at boot, shows their state, and manages other kinds of units such as timers, sockets, mounts and targets.

A unit is a configuration file that describes one thing systemd manages; a service unit is named name.service (the suffix is optional for services: systemctl status nginx). Unit files supplied by packages live in /usr/lib/systemd/system/; your own and local overrides go in /etc/systemd/system/.

Terminal
systemctl status nginx
sudo systemctl restart nginx
sudo systemctl enable --now nginx
systemctl list-units --type=service --state=failed

Try it

The sandbox does not run systemd, so systemctl has nothing to talk to. These examples are read-only: they write a sample unit file and a sample systemctl status output, and parse them.

Bash Reading a unit file (sample)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Checking whether systemd is running (works anywhere)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
systemctl [OPTION]... COMMAND [UNIT]...
Command Description
start, stop, restart Run, stop, or stop and start a unit now.
reload Ask the service to re-read its configuration without stopping.
try-restart, reload-or-restart Restart only if running; reload if supported, otherwise restart.
enable, disable Add or remove the unit from boot targets (symlinks). --now also starts or stops it.
status State, recent log lines, main process.
is-active, is-enabled, is-failed Print one word and set an exit status (useful in scripts).
mask, unmask Make a unit impossible to start (link to /dev/null), or undo it.
list-units, list-unit-files Loaded units, or all installed unit files and their enablement.
list-timers Scheduled timer units and when they fire next.
daemon-reload Re-read unit files after you edit them.
edit UNIT Create a drop-in override (--full edits a copy of the whole file).
cat UNIT, show UNIT Print the unit file, or all properties.
--user Manage the per-user service manager instead of the system one.
-t TYPE, --failed, --no-pager Filter by unit type, list failed units, and skip the pager.

Returns: 0 on success. is-active returns 0 only when active, and status returns 3 for an inactive unit and 4 for an unknown one.

Usage notes

  • enable is not start. enable only affects the next boot; use enable --now for both.
  • Run daemon-reload after editing a unit file, otherwise systemd keeps using the old copy (it warns in status).
  • Never edit files under /usr/lib/systemd/system/. A package update would overwrite them. Use systemctl edit nginx, which writes /etc/systemd/system/nginx.service.d/override.conf.
  • reload versus restart: reload keeps connections open but works only if the unit defines ExecReload; check the unit before relying on it.
  • Failed service? Run systemctl status UNIT and then journalctl -u UNIT -b, which show the exit code and the program's own messages.
  • Root is needed to change system units; status and list-* work for everyone. Use sudo or --user.
  • Common unit settings: Type=simple|forking|oneshot|notify, Restart=on-failure, User=, WorkingDirectory=, Environment=, After=/Requires= for order and dependencies, WantedBy=multi-user.target for starting at boot.
  • Targets replace runlevels: multi-user.target is the text-mode system and graphical.target adds a desktop. systemctl get-default shows the current one.
  • Containers and WSL often lack systemd; then systemctl fails with "System has not been booted with systemd".