fbpx Mastering systemd Units and Timers: Practical Sysadmin Guide | Certificação Linux

Mastering systemd Units and Timers: Practical Guide for Sysadmins

📅 07/19/2026 ⏱ 5 min ✍️ Uira Ribeiro
Mastering systemd Units and Timers: Practical Guide for Sysadmins
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

Efficiently managing services and scheduled tasks is crucial for any sysadmin or DevOps engineer. This article solves the problem of how to master systemd units and timers on Linux, explaining not just the 'how to', but also the 'why it works this way'. Understanding these concepts is vital to optimizing service management and automation in Linux environments.

What are systemd units?

Systemd units are the basic entities of systemd, the modern replacement for SysVinit. Each unit represents a service, mount, socket, device, or timer. Systemd uses these units to manage and start services during boot and to keep the system in a desired state.

Each unit is defined in a .service, .mount, .socket, etc. file, located in /etc/systemd/system/ or /usr/lib/systemd/system/. These files are written in an INI format and contain sections like [Unit], [Service], and [Install].


[Unit]
Description=Example Service
After=network.target

[Service]
ExecStart=/usr/bin/example
Restart=always

[Install]
WantedBy=multi-user.target

In this example, the unit defines a service that starts after the network is ready (After=network.target), executes the /usr/bin/example command, and restarts whenever it fails (Restart=always).

How to create and manage systemd units

To create a new unit, you can manually write a .service file or use tools like systemctl edit to create an override. After creating or modifying a unit, you must reload the systemd configuration with systemctl daemon-reload.


# Criar um novo serviço
sudo systemctl edit example.service

# Adicionar o conteúdo da unit
[Service]
ExecStart=/usr/bin/example

# Recarregar a configuração
sudo systemctl daemon-reload

# Habilitar e iniciar o serviço
sudo systemctl enable example.service
sudo systemctl start example.service

After running these commands, the service will be enabled to start on boot and will begin executing immediately. You can check the service status with systemctl status example.service.

Understanding systemd timers

Systemd timers are used to schedule recurring tasks, similar to cron jobs, but with more flexibility and integration with systemd. Each timer is associated with a unit, which is activated when the timer fires.


[Unit]
Description=Run example daily

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

In this example, the timer is configured to fire daily (OnCalendar=daily) and the Persistent=true flag ensures the task will be executed even if the system is shut down at the scheduled time.

How to create and manage systemd timers

To create a timer, you must first create the associated unit and then create the timer file. After creating both, you must enable and start the timer.


# Criar a unit associada
sudo systemctl edit example.service

# Adicionar o conteúdo da unit
[Service]
ExecStart=/usr/bin/example

# Criar o timer
sudo systemctl edit example.timer

# Adicionar o conteúdo do timer
[Unit]
Description=Run example daily

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

# Recarregar a configuração
sudo systemctl daemon-reload

# Habilitar e iniciar o timer
sudo systemctl enable example.timer
sudo systemctl start example.timer

With these commands, the timer will be enabled to start on boot and will begin counting down to the next firing. You can check the timer status with systemctl status example.timer.

Differences between systemd and SysVinit

Systemd offers several advantages over SysVinit, including parallel service startup, clearer dependencies, and socket and device management. While SysVinit uses scripts in /etc/init.d/ and runlevels, systemd uses units and targets to manage system state.

Additionally, systemd provides a D-Bus API for interacting with services and timers, enabling deeper integration with other tools and scripts. This makes systemd more suitable for modern systems that require high availability and scalability.

Parallel vs sequential startup

One of the main differences between systemd and SysVinit is how services are started. SysVinit starts services sequentially, which can result in longer boot times. On the other hand, systemd starts services in parallel, which significantly reduces boot time.

Common Pitfalls and How to Avoid Them

  • Forgetting to reload the configuration: After creating or modifying a unit or timer, it is crucial to reload the systemd configuration with systemctl daemon-reload. Forgetting this step will result in errors when trying to enable or start the unit.
  • Using incorrect absolute paths: Make sure the paths specified in ExecStart and other fields are correct. Incorrect paths will result in failures when starting the service.
  • Ignoring dependencies: Setting correct dependencies in After= and Before= is crucial to ensure services are started in the correct order. Ignoring dependencies can lead to failures and unexpected behavior.
  • Forgetting to enable the timer: After creating a timer, it is necessary to enable it with systemctl enable so it will be activated on boot. Forgetting this step will result in timers that do not fire.
  • Using incorrect syntax in timers: The syntax for timers can be complex. Make sure to follow the official documentation and test timers in a development environment before putting them into production.

On the LPI / CompTIA Linux+ Exam

In certifications like LPI and CompTIA Linux+, it is common to find questions about systemd units and timers. Candidates should be familiar with:

  • Creating and editing units and timers
  • Basic commands like systemctl start, systemctl enable, and systemctl status
  • Differences between systemd and SysVinit
  • Managing dependencies and startup order

Conclusion

Mastering systemd units and timers is essential for any sysadmin or DevOps engineer working with Linux systems. This article provided a practical and detailed approach to creating, managing, and understanding these concepts. By following the described steps and avoiding common pitfalls, you will be well prepared to optimize service management and scheduled tasks in your Linux environments.

The next steps include practicing the creation and management of units and timers in development environments and gradually migrating to production environments. Stay updated with the official systemd documentation and explore advanced features, such as sockets and mount units, to further enhance your skills.

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp