Introduction / Why This Is Needed
Systemd has become the standard for managing services and processes in most modern Linux distributions (Ubuntu, Fedora, CentOS/RHEL 8+, Debian 10+). Understanding its fundamentals is an essential skill for a system administrator and developer working with servers.
This guide will provide you with practical skills for everyday service management: starting, stopping, configuring autostart, and diagnosing failures. You will be able to confidently work with commands such as systemctl and journalctl.
Requirements / Preparation
- A Linux distribution with the systemd initialization system (check with:
pidof systemd). - Terminal access with sudo privileges (for managing system services).
- Basic understanding of the command line.
Step 1: Basic Service State Management Commands
Systemctl is the primary tool for interacting with systemd. Here are the key commands for managing service state:
- Start a service:
Example:sudo systemctl start имя_службы.servicesudo systemctl start nginx - Stop a service:
sudo systemctl stop имя_службы.service - Restart a service (graceful):
sudo systemctl restart имя_службы.service - Forceful restart (kill and start):
sudo systemctl try-restart имя_службы.service💡 Tip: For web servers (nginx, apache), after changing the configuration, use
reload(sudo systemctl reload nginx) to reread the config without dropping connections.
Step 2: Managing Autostart (Enable/Disable)
For a service to start automatically at system boot, it must be enabled.
- Enable autostart:
This command creates a symbolic link to the unit file in thesudo systemctl enable имя_службы.service/etc/systemd/system/directory. - Disable autostart:
sudo systemctl disable имя_службы.service - Check if a service is enabled for autostart:
Output:systemctl is-enabled имя_службы.serviceenabled(enabled),disabled(disabled),static(cannot be enabled directly but can be a dependency),masked(completely blocked).
Step 3: Viewing Status and All Services
- Detailed status of a specific service:
The output shows:systemctl status имя_службы.serviceActive:(state),Main PID:(process identifier), and the last lines of the service's journal. - List all loaded (active) units:
systemctl list-units --type=service - List ALL available services (including inactive ones):
systemctl list-units --type=service --all - Search for a service by name:
systemctl list-units --type=service --all | grep -i ssh
Step 4: Analyzing Logs with journalctl
Systemd logs are stored in a binary journal, accessible via journalctl.
- View logs for a specific service:
sudo journalctl -u имя_службы.service - Follow logs in real-time (like
tail -f):sudo journalctl -u имя_службы.service -f - Logs from the last system boot:
sudo journalctl -b - Logs filtered by time:
sudo journalctl --since "2026-02-15 10:00:00" --until "2026-02-15 12:00:00" - Show logs with maximum verbosity for a service:
sudo journalctl -u имя_службы.service -o verbose
Step 5: Additional Operations (Reload Configuration, Masking)
- Reload systemd configuration (mandatory after creating/modifying unit files):
sudo systemctl daemon-reload - Full service block (mask) — prevents any manual or automatic start:
Creates a symbolic link tosudo systemctl mask имя_службы.service/dev/null. To unmask:sudo systemctl unmask имя_службы.service. - Force stop and reset service state:
Useful if a service is in asudo systemctl reset-failed имя_службы.servicefailedstate and won't start after fixing the error.
Verification
- To verify operation: run
systemctl status имя_службы. Ensure theActive:line containsactive (running). - To verify autostart: reboot the system (
sudo reboot) and after logging in, check the service status. - To verify logs: ensure
journalctl -u имя_службыshows no errors (failed,error,permission denied).
Potential Issues
- Error
Failed to start ...orUnit not found.- Cause: The unit file is missing or has an incorrect name. Ensure the service exists:
systemctl list-unit-files | grep имя_службы. Check the unit file syntax:sudo systemd-analyze verify /etc/systemd/system/имя_службы.service.
- Cause: The unit file is missing or has an incorrect name. Ensure the service exists:
- Service starts but immediately stops.
- Cause: An error in the application itself or incorrect parameters in the
[Service]section (e.g.,ExecStartpoints to a non-existent binary). Check detailed logs:sudo journalctl -u имя_службы.service -n 50 --no-pager.
- Cause: An error in the application itself or incorrect parameters in the
Permission deniedwhen trying to manage a system service.- Cause: You are running the command without
sudo. Managing system services (from/etc/systemd/system/) requires root privileges.
- Cause: You are running the command without
- Service does not enable for autostart (
enablefails).- Cause: The unit file has an
[Install]section but lacksWantedBy=orRequiredBy=(most commonlyWantedBy=multi-user.target). Add this line to the unit file and rundaemon-reloadandenableagain.
- Cause: The unit file has an
- Restart loops (cyclic restarts).
- Cause: The
[Service]section in the unit file containsRestart=always(oron-failure), and the process exits immediately with an error. Fix the application error or temporarily comment outRestartfor diagnostics.
- Cause: The