3v-Hosting Blog
Manage Systemd Services with systemctl on Linux
8 min read
The Linux ecosystem has evolved significantly in terms of service management. Traditional init scripts were the go-to for many years, but the introduction of systemd marked a major shift. It is clear that today, most modern Linux distributions, including Ubuntu, Debian, Fedora, and CentOS, use systemd as the default init system. systemd is a powerful system that provides complete control over services and their lifecycle through a powerful utility called systemctl. Any system administrator, developer, or hosting engineer must understand how to work with it.
What is systemd and systemctl
Systemd is an init system and service manager. It boots up Linux systems, handles processes, mounts file systems, and manages background daemons. systemd uses unit files to define services and dependencies, which is a clear improvement over older init systems. Each process, socket, mount, or timer is treated as a unit, and systemd ensures proper startup and dependency resolution.
Use systemctl as the primary command-line interface for interacting with systemd. With it, administrators can start, stop, restart, reload, enable, or disable services, as well as monitor their status. This makes it an indispensable tool in everyday Linux server administration.
Checking the Status of Services
The most common task is checking whether a service is running. The command:
systemctl status nginx
shows detailed information, including whether the service is active, its PID, recent logs, and whether it is enabled at boot. This output is much more informative than legacy init scripts, allowing administrators to quickly diagnose issues.
Using systemctl status is often the first step in troubleshooting, as it reveals both the state of the service and recent errors. Combined with journalctl, which shows historical logs, it becomes a powerful diagnostic tool.
Starting and Stopping Services
When you want to run a service, you use:
sudo systemctl start service_name
To stop it, the command is:
sudo systemctl stop service_name
These actions are temporary. If you restart the server, the service will not automatically start unless it has been explicitly enabled. This behavior allows administrators to test configurations without permanently altering system startup.
For example, a web server or database may be started manually for testing, and later disabled to avoid unnecessary resource consumption.
Restarting and Reloading
Restarting services is a very common action during system administration. If you made changes to a configuration file and need them applied, you would usually execute:
sudo systemctl restart apache2
or simply systemctl restart service if you substitute the actual name. This command stops and starts the service completely.
However, some services support reloading their configuration without a full restart. This is where systemctl reload becomes useful. For example, Nginx or Postfix can reload new configuration without dropping active connections:
sudo systemctl reload nginx
It is important to understand the difference: a restart is disruptive, while a reload is graceful. Administrators must check documentation for each daemon to see whether reload is supported. If not, a restart remains the only option.
In cases where systemd itself must re-read unit files (for example, when you have just modified a .service file), you need to execute:
sudo systemctl daemon-reload
This is sometimes referred to as systemctl reload daemon, and it ensures systemd is aware of new or updated unit definitions.
Other useful articles in our Blog:
- What Are ChatGPT’s Limits?
- Best VPS for Game Servers (Minecraft, CS:GO, Valheim): Performance, Setup, and Comparison
- How to Create a Discord Bot
- How to Stop a DDoS Attack
Enabling and Disabling Services
By default, starting a service does not guarantee it will run after reboot. To configure this behavior, you use:
sudo systemctl enable service_name
This creates symbolic links in systemd directories so the service will automatically launch during boot. Conversely, if you want to prevent a service from starting automatically:
sudo systemctl disable service_name
This approach gives fine-grained control over which processes run persistently. For example, a developer might enable Docker on a development server, while keeping experimental applications disabled.
In environments where uptime and predictability are critical, understanding how systemctl enable and disable interact with dependencies is essential.
Listing Services and Monitoring
System administrators often need an overview of all running and inactive services. The command:
systemctl list-units --type=service
or more simply systemd list services, shows the full state of system services. Active, failed, or inactive units are all listed, allowing quick identification of problems.
Another useful variant is:
systemctl --failed
which highlights only failed services. This can help during troubleshooting after a reboot, when some services may not have started due to configuration errors.
Practical Scenarios
In real-world hosting and administration, systemctl is used constantly. For example:
- After editing an Nginx configuration file, you might test it, then use systemctl reload nginx to apply changes without downtime.
- If a database has hung, you would issue systemctl restart mysql to reset it.
- During troubleshooting, systemctl status provides quick insight into why a service failed.
- To ensure a background service like Redis always runs on boot, administrators rely on systemctl enable redis-server.
- When a service consumes too many resources, systemctl stop service halts it immediately.
These examples show how tightly systemctl is integrated into Linux administration workflows.
Systemd Units Beyond Services
While this article focuses on services, it is worth noting that systemd manages many other types of units, such as sockets, devices, mounts, automounts, timers, and targets. Systemctl commands are consistent across these unit types, which makes systemd a unified management framework for the entire operating system.
For example, scheduled tasks can be managed with systemd timers instead of cron, and socket-based activation can delay service startup until the first incoming connection. This demonstrates how systemd provides both simplicity and advanced flexibility.
Conclusion
Systemctl has become the standard tool for service management on Linux. By mastering commands like systemctl status, systemctl restart, systemctl reload, systemctl enable, and systemctl stop service, administrators gain reliable control over system behavior. Understanding the differences between restart and reload, temporary and permanent changes, and how to list and diagnose services ensures stable and secure operation of Linux environments.
Whether you are managing a single development machine or a cluster of production servers, systemd and systemctl form the backbone of modern Linux service management. They replace the fragmented tools of the past with a unified and powerful interface, making administration more predictable, transparent, and efficient.