In this lesson, you will learn how to bridge the gap in your task scheduling by using the Persistent directive to ensure that jobs missed while the system was powered down execute immediately upon boot.
The Challenge of Downtime
When you define a systemd calendar timer (e.g., a job set to run daily at 3:00 AM), systemd expects the machine to be running at that specific moment. If your server is powered off, rebooting, or in a suspended state during that scheduled window, the timer simply skips the execution. Unlike traditional cron, which often relies on anacron to catch up on missed tasks, systemd timers require explicit configuration to handle these "dark periods."
Enabling Persistence
To force the system to check if a task was missed while the machine was off, you must modify your .timer unit file. By adding Persistent=true to the [Timer] section, you instruct the system to compare the current time against the last successful execution time upon startup.
If the time elapsed since the last run is greater than the interval defined in your OnCalendar directive, the system will trigger the task immediately after the boot process completes.
Implementation Example
To configure a backup script to run daily but execute on boot if the window was missed, edit your timer file:
[Unit]
Description=Daily Backup Timer
[Timer]
OnCalendar=daily
Persistent=true
Unit=backup.service
[Install]
WantedBy=timers.target
Why This Matters
When you set Persistent=true, you remove the unpredictability of system downtime. This is vital for maintenance tasks like log rotation, security patching, or database synchronization that are sensitive to timing but must guarantee eventual completion. Note that if you have multiple missed intervals—for example, if a machine was off for three days—systemd will trigger the job only once upon boot to catch up, rather than queueing three separate executions.
Key Takeaway: Setting Persistent=true in your systemd timer unit bridges the gap caused by system downtime, ensuring your automated tasks trigger immediately upon next boot if their scheduled interval was missed.