systemctl

Is the service running? Start it, restart it, make it start at boot — and read why it failed with journalctl.

>_ Try it: a simulated Linux, right here
Loading the terminal…

Examples

  • sudo systemctl start nginx
  • systemctl is-active nginx
  • sudo systemctl enable nginx
  • journalctl -u nginx -n 5
  • systemctl list-units --type=service
  • curl localhost

How it works

On most Linux servers (Ubuntu, Debian, Fedora…) systemd runs the services: the web server, ssh, cron. systemctl is how you talk to it.

status shows if a service runs, since when, and its last log lines. Changing a service needs root: sudo systemctl restart nginx. start is about now; enable is about the next boot.

Syntax

systemctl COMMAND [SERVICE]...

Options

OptionWhat it does
statusrunning or not, since when, the last log lines
start / stop / restartstart, stop, or stop + start (needs root)
enable / disablestart at every boot, or not (needs root)
is-activejust "active" or not: handy in scripts
--nowwith enable / disable: also start / stop it now
journalctl -uthe full log of one service (journalctl)

Good to know

  • A service that won't start says why in its logs: journalctl -u nginx — read it before restarting again.
  • In containers (like docker-lab) there is no systemd: systemctl answers "System has not been booted with systemd".