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/.
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.
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.
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
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
enableis notstart.enableonly affects the next boot; useenable --nowfor both.- Run
daemon-reloadafter editing a unit file, otherwise systemd keeps using the old copy (it warns instatus). - Never edit files under
/usr/lib/systemd/system/. A package update would overwrite them. Usesystemctl edit nginx, which writes/etc/systemd/system/nginx.service.d/override.conf. reloadversusrestart: reload keeps connections open but works only if the unit definesExecReload; check the unit before relying on it.- Failed service? Run
systemctl status UNITand thenjournalctl -u UNIT -b, which show the exit code and the program's own messages. - Root is needed to change system units;
statusandlist-*work for everyone. Usesudoor--user. - Common unit settings:
Type=simple|forking|oneshot|notify,Restart=on-failure,User=,WorkingDirectory=,Environment=,After=/Requires=for order and dependencies,WantedBy=multi-user.targetfor starting at boot. - Targets replace runlevels:
multi-user.targetis the text-mode system andgraphical.targetadds a desktop.systemctl get-defaultshows the current one. - Containers and WSL often lack systemd; then
systemctlfails with "System has not been booted with systemd".