Linux

Managing systemd Services: A Comprehensive Guide to Starting, Stopping, and Configuring

In this guide, you''ll master essential systemctl commands for managing services in modern Linux distributions. Learn to start, stop, enable autostart for services, and diagnose issues.

Updated at February 16, 2026
15-30 min
Medium
FixPedia Team
Применимо к:Ubuntu 20.04+CentOS/RHEL 8+Debian 10+Fedora

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:
    sudo systemctl start имя_службы.service
    
    Example: sudo 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:
    sudo systemctl enable имя_службы.service
    
    This command creates a symbolic link to the unit file in the /etc/systemd/system/ directory.
  • Disable autostart:
    sudo systemctl disable имя_службы.service
    
  • Check if a service is enabled for autostart:
    systemctl is-enabled имя_службы.service
    
    Output: enabled (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:
    systemctl status имя_службы.service
    
    The output shows: Active: (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:
    sudo systemctl mask имя_службы.service
    
    Creates a symbolic link to /dev/null. To unmask: sudo systemctl unmask имя_службы.service.
  • Force stop and reset service state:
    sudo systemctl reset-failed имя_службы.service
    
    Useful if a service is in a failed state and won't start after fixing the error.

Verification

  1. To verify operation: run systemctl status имя_службы. Ensure the Active: line contains active (running).
  2. To verify autostart: reboot the system (sudo reboot) and after logging in, check the service status.
  3. To verify logs: ensure journalctl -u имя_службы shows no errors (failed, error, permission denied).

Potential Issues

  • Error Failed to start ... or Unit 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.
  • Service starts but immediately stops.
    • Cause: An error in the application itself or incorrect parameters in the [Service] section (e.g., ExecStart points to a non-existent binary). Check detailed logs: sudo journalctl -u имя_службы.service -n 50 --no-pager.
  • Permission denied when trying to manage a system service.
    • Cause: You are running the command without sudo. Managing system services (from /etc/systemd/system/) requires root privileges.
  • Service does not enable for autostart (enable fails).
    • Cause: The unit file has an [Install] section but lacks WantedBy= or RequiredBy= (most commonly WantedBy=multi-user.target). Add this line to the unit file and run daemon-reload and enable again.
  • Restart loops (cyclic restarts).
    • Cause: The [Service] section in the unit file contains Restart=always (or on-failure), and the process exits immediately with an error. Fix the application error or temporarily comment out Restart for diagnostics.

F.A.Q.

How to check if a systemd service is running?
How does systemd differ from old init scripts (SysVinit)?
How to create your own unit file for a service?
Why doesn''t the service start at boot even though it''s enabled via systemctl enable?

Hints

Check service status
Basic management (start, stop, restart)
Managing autostart
Viewing all services and filtering
Working with logs (journalctl)
Reloading the systemd daemon

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community