systemd tutorial: manage services from scratch
Learn how to start, stop, enable, disable, and inspect systemd services on a Linux server.
- systemd tutorial: manage services from scratch
- What You Will Need
- Step 1: Check Whether a Service Is Running with systemctl
- Step 2: Start and Stop a Service with systemctl
- Step 3: Enable a Service to Start at Boot with systemctl
- Step 4: Restart and Reload a Service with systemctl
- Step 5: View Logs for a Service with journalctl
- What You Learned
systemd tutorial: manage services from scratch
Learn how to start, stop, enable, disable, and inspect systemd services on a Linux server.
What You Will Need
- A Linux server running systemd (Ubuntu 20.04+, Debian 10+, RHEL 8+, or Fedora).
- Root or sudo access.
- A running service to practice with (this tutorial uses Nginx as an example).
Step 1: Check Whether a Service Is Running with systemctl
systemd tracks the state of every managed service. The
systemctl status command shows whether a service is active (running), inactive (stopped), or failed:
systemctl status nginx.serviceThe output includes the loaded state (whether systemd found the unit file), the active state (whether the service is running), the main PID, memory usage, and the most recent log lines. Understanding this output is the first skill for managing systemd services.
Step 2: Start and Stop a Service with systemctl
systemd starts a stopped service with
systemctl start and stops a running service with
systemctl stop:
sudo systemctl start nginx.service
sudo systemctl stop nginx.serviceThese commands change the runtime state only. They do not affect what happens at boot. Starting a service that is already running has no effect — systemd recognizes the service is active and takes no action.
Step 3: Enable a Service to Start at Boot with systemctl
systemd controls boot behavior through symlinks.
systemctl enable creates a symlink that causes systemd to start the service automatically when the system boots:
sudo systemctl enable nginx.servicesystemctl disable removes the symlink. The service continues running until stopped manually, but it will not start on the next boot:
sudo systemctl disable nginx.serviceThe
--now flag combines enable/disable with start/stop in a single command.
Step 4: Restart and Reload a Service with systemctl
systemctl restart stops and starts a service in sequence. Use it after changing the service binary or unit file:
sudo systemctl restart nginx.servicesystemctl reload sends a signal (usually SIGHUP) to the running process, asking it to re-read its configuration without stopping. Not all services support reload:
sudo systemctl reload nginx.servicesystemctl reload-or-restart attempts a reload first and falls back to a full restart if the service does not support reload.
Step 5: View Logs for a Service with journalctl
systemd captures stdout and stderr from every service into the journal. The
journalctl -u command filters log entries by service name:
journalctl -u nginx.service --since "10 minutes ago"This replaces the need to search through separate log files in
/var/log/. The journal includes timestamps, priority levels, and the service name on every line.
What You Learned
This tutorial covered the five core systemctl operations:
status (inspect),
start/
stop (runtime control),
enable/
disable (boot behavior),
restart/
reload (apply changes), and
journalctl -u (log inspection). These commands form the foundation for managing any systemd service on Linux.