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 herenothing runs on your computer
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
| Option | What it does |
|---|---|
status | running or not, since when, the last log lines |
start / stop / restart | start, stop, or stop + start (needs root) |
enable / disable | start at every boot, or not (needs root) |
is-active | just "active" or not: handy in scripts |
--now | with enable / disable: also start / stop it now |
journalctl -u | the 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:
systemctlanswers "System has not been booted with systemd".