Marcio Cunha

Systemd on Ubuntu Server: how services are started and managed

Explore how systemd operates at the core of Ubuntu Server, managing operating system startup, process dependencies, and the lifecycles of essential background services.

Marcio Cunha12 min
Also available in:EspañolPortuguês
Summary
  • Systemd replaced the legacy SysVinit model to accelerate system boot times and manage background processes concurrently.
  • Units known as unit files dictate the behavior, file paths, and restart rules for every running service on the server.
  • The journald daemon centralizes system logging, allowing precise troubleshooting through advanced filters by time and severity.
  • Strict dependency management prevents applications from launching before network interfaces and storage are fully operational.
  • Native utilities like systemctl control daemon states directly from the terminal without relying on complex shell scripts.

The Evolution of Linux Initialization and the Role of systemd

When you boot an Ubuntu server, the very first process executed by the kernel receives the numerical identifier one, commonly known as PID 1. Historically, this position was held by SysVinit, a sequential system that executed shell scripts line by line to load essential components. In practice, this meant slow boot times, because if a network disk took too long to respond, the entire process stalled waiting for it. Systemd emerged to solve this inefficiency by adopting a parallel, event-driven approach to operating system management.

Instead of queuing tasks rigidly, systemd maps out dependencies among components. It triggers a service only when necessary resources, such as network interfaces or storage mount points, are physically ready. This mechanism drastically reduces boot times and brings greater predictability to production environments. For engineers and system administrators, understanding this machinery is essential for diagnosing failures and optimizing servers running critical applications.

Anatomy of a Unit and Configuration Files

In the systemd ecosystem, almost everything is treated as a unit. These units are classified into types, with service files identified by the .service extension being the most common in infrastructure workflows. In practice, these files act as detailed recipes telling the operating system precisely how a program should be started, monitored, paused, and terminated. They reside in standard system directories, such as /lib/systemd/system/ for package manager installations and /etc/systemd/system/ for local administrator adjustments.

A typical unit file is divided into well-defined sections, including [Unit], [Service], and [Install]. The [Unit] section describes the service's purpose and establishes precedence rules, indicating, for example, that it should run only after the network is active. The [Service] section defines the exact command to execute, the system user under which the process will run, and the restart policy for unexpected crashes. Finally, the [Install] section guides systemd on which target state the service should join when enabled.

To illustrate the structure of a custom service file, consider the practical example below configuring a generic web application running in the background:

[Unit] 
Description=Example Web Application 
After=network.target 

[Service] 
Type=simple 
User=www-data 
ExecStart=/usr/bin/python3 /var/www/app/main.py 
Restart=on-failure 

[Install] 
WantedBy=multi-user.target

In this example, the After directive ensures the application only starts running after the network is available. The line Restart=on-failure instructs systemd to attempt automatic recovery if the process exits with an unexpected error code, increasing environment resilience without immediate human intervention.

The Lifecycle and Practical Control with systemctl

Managing the daily behavior of daemons on Ubuntu Server requires mastering the systemctl command, the official command-line interface to interact with systemd. Through it, operators can verify service health, apply configuration updates without rebooting the entire machine, and quickly isolate failures. When a service exhibits instability, the status command offers a comprehensive overview containing the current PID, recent memory consumption, and the latest log lines generated by the process.

The table below summarizes the most frequently used commands in the daily operational workflow of a modern Linux server:

Operational Actionsystemctl CommandPractical Effect on Server
Start servicesudo systemctl start namePuts the process into execution immediately.
Stop servicesudo systemctl stop nameTerminates the process in a controlled manner.
Enable on bootsudo systemctl enable nameCreates symlinks to start automatically at boot.
Reload configssudo systemctl daemon-reloadNotifies systemd about changes in unit files.

Mastering these commands reduces mean time to resolution during infrastructure incidents. Whenever you manually modify a service file inside the /etc/systemd/system/ directory, executing the daemon-reload command is a mandatory step so the manager recognizes the new guidelines before attempting to restart the affected daemon.

Log Monitoring and Diagnostics with journald

Managing processes without proper visibility into their event logs is like navigating in the dark. Systemd solves this through journald, its native log collection and storage subsystem. Unlike traditional text files scattered across the /var/log/ directory, journald captures standard output and errors from all managed services, compressing this data into an indexed binary format optimized for rapid querying.

To check the history of a specific service at runtime, administrators use the journalctl command filtered by unit name. In practice, this isolates the noise generated by other operating system components and focuses exclusively on the target application's behavior. The command journalctl -u nginx.service -f, for example, displays web server logs in real time, facilitating immediate tracking of request errors or configuration bugs.

Beyond real-time monitoring, the utility features advanced chronological and severity-level filtering capabilities. You can list only critical errors occurring since the last boot using parameters like --since today and -p err. This structured approach accelerates bottleneck identification and anomalous behavior in high-demand enterprise environments.

Final Thoughts on Infrastructure Management

Systemd has established itself as the backbone of the modern Linux ecosystem, unifying initialization, process control, and event logging into a cohesive architecture. Understanding its inner workings on Ubuntu Server transforms how engineers design, deploy, and maintain applications in production, replacing makeshift scripts with a deterministic and robust model.

Investing time in the detailed study of units, dependencies, and recovery policies reduces operational failures and brings greater predictability to systems. With a solid foundation in systemd operations, technology teams gain the autonomy to manage complex workloads with total confidence and operational efficiency.