The Evolution from Init to Systemd
For decades, Linux distributions managed background services (daemons) using the legacy SysV init system. Administrators would start or stop the Apache web server using scripts located in /etc/init.d/, or by using the service command (e.g., service apache2 restart).
Today, virtually every modern Linux distribution—including Ubuntu, Debian, CentOS, and Red Hat—has migrated to a unified initialization and service manager called systemd. The core utility used to interact with systemd is systemctl. If you are managing a modern Linux server, mastering systemctl is an absolute requirement.
Checking Service Status
Before modifying a service, you should check its current state. Is it actively running? Has it crashed? Is it configured to launch automatically on boot?
To check the status of a service (for example, the sshd secure shell daemon), use the status command:
sudo systemctl status sshd
The output provides a wealth of information. You will see a green active (running) indicator if the service is healthy, the exact path to its configuration file, its current PID (Process ID), and crucially, the last ten lines of its log output directly from the system journal, which is invaluable for immediate troubleshooting.
Starting, Stopping, and Restarting
The syntax for controlling the execution state of a daemon is straightforward. You must use sudo because you are altering system-level processes.
- To start a service immediately:
sudo systemctl start nginx - To gracefully stop a running service:
sudo systemctl stop nginx - To forcefully terminate and restart a service:
sudo systemctl restart nginx
The Power of Reload
If you edit a configuration file (like adding a new virtual host to Nginx), you usually do not want to use restart. A restart completely kills the process, instantly dropping all active client connections. Instead, you should use reload.
sudo systemctl reload nginx
The reload command sends a SIGHUP signal to the daemon. The daemon will gracefully finish processing current connections while simultaneously reading the new configuration file into memory for new connections, resulting in zero downtime.
Managing Boot Behavior (Enable/Disable)
Just because a service is running right now does not mean it will automatically start if the server loses power and reboots. You must explicitly tell systemd to hook the service into the boot sequence.
To ensure a service starts automatically on every boot, use enable:
sudo systemctl enable mariadb
This command creates a symlink in the systemd configuration directories, linking the service to the multi-user target.
Conversely, to prevent a service from launching at boot (useful for security or saving RAM), use disable:
sudo systemctl disable mariadb
Note: Disabling a service does not stop it if it is currently running. You must run systemctl stop mariadb separately.