База знань

How to List and Manage Linux Services with systemctl

On modern Linux (Ubuntu, Debian, AlmaLinux, CentOS), systemd manages background services and you control them with the systemctl command. This guide covers listing, starting, stopping and troubleshooting services.

1. List services

systemctl list-units --type=service            # running services
systemctl list-units --type=service --all      # all, including stopped
systemctl list-unit-files --type=service       # every installed service + boot state
systemctl --failed                             # only failed services

2. Check a service’s status

systemctl status nginx        # detailed status + recent log lines
systemctl is-active nginx     # active / inactive
systemctl is-enabled nginx    # enabled / disabled at boot

3. Start, stop, restart, reload

sudo systemctl start nginx     # start now
sudo systemctl stop nginx      # stop now
sudo systemctl restart nginx   # restart
sudo systemctl reload nginx    # reload config without dropping connections

4. Enable or disable at boot

sudo systemctl enable nginx        # start automatically at boot
sudo systemctl disable nginx       # don't start at boot
sudo systemctl enable --now nginx  # enable AND start immediately
sudo systemctl disable --now nginx # disable AND stop immediately

5. Mask a service (prevent it from starting)

sudo systemctl mask apache2     # fully block a service
sudo systemctl unmask apache2   # allow it again

6. View service logs

journalctl -u nginx             # all logs for a service
journalctl -u nginx -f          # follow live (Ctrl+C to stop)
journalctl -u nginx --since "1 hour ago"
journalctl -u nginx -p err      # only errors

7. After editing a service file

sudo systemctl daemon-reload    # reload systemd after changing unit files

Tip: replace nginx with any service — e.g. mysql, php-fpm, ssh, cron. Use systemctl status <service> first whenever something isn’t working — it shows whether the service is running and the last error lines.

Ця відповідь Вам допомогла?

0 Користувачі, які знайшли це корисним

Powered by WHMCompleteSolution