Testing scheduled jobs on dedicated servers: catch-up runs, time zones and failures

Testing scheduled jobs on dedicated servers: catch-up runs, time zones and failures

Testing scheduled jobs on dedicated servers: catch-up runs, time zones and failures

An overnight report is missing, yet its timer still shows as active. Often, the scheduler has not stopped: the service has failed, or the job’s expectations about a missed run do not match the scheduler’s behavior. Scheduled jobs on a dedicated server need separate acceptance checks for trigger times, catch-up behavior and business results. The presence of a configuration file is not proof of a successful deployment. The following procedure uses systemd on Debian 12 to create an isolated test job that does not touch business data.

Define the time zone and catch-up behavior first

Start by documenting the job’s contract: which time zone controls its schedule, whether it should catch up after being disabled, whether repeated execution is safe, and who handles failures. This example uses a calendar timer that runs once a day at 02:15 UTC, without changing the server’s time zone.

timedatectl status
systemd-analyze calendar --iterations=5 '*-*-* 02:15:00 UTC'

The first command checks the system clock and synchronization status; the second shows the next scheduled trigger times. Quote the calendar expression to prevent the shell from expanding the asterisks. If the system clock is unreliable, resolve time synchronization before assessing whether the job runs on time.

Specifying UTC explicitly prevents the business schedule from shifting with local daylight saving time. If the job genuinely follows a regional business calendar, use the corresponding time zone and separately test skipped and repeated local times. The application’s internal “business date” must follow the same convention rather than relying directly on the local time inherited by the process.

Persistent=true is not a job queue. It can schedule one catch-up run for a timer that missed calendar triggers, but it does not replay every scheduled time during the inactive period or automatically retry failed business operations.

Processes such as daily reports and billing summaries should record completed intervals and let the application calculate any gaps. Simply using “the current date minus one day” is not a substitute for complete catch-up logic.

Create test units with no business side effects

The following commands create dedicated test files and must not overwrite existing production units. The test service only appends timestamps to its own state directory, making it possible to distinguish a scheduler trigger from an actual write to disk.

sudo tee /etc/systemd/system/timer-proof.service >/dev/null <<'EOF'
[Unit]
Description=Timer acceptance probe

[Service]
Type=oneshot
DynamicUser=yes
StateDirectory=timer-proof
ExecStart=/bin/sh -c '/usr/bin/date -Iseconds >> /var/lib/timer-proof/runs'
EOF

sudo tee /etc/systemd/system/timer-proof.timer >/dev/null <<'EOF'
[Unit]
Description=Calendar timer acceptance probe

[Timer]
OnCalendar=*-*-* 02:15:00 UTC
Persistent=true
AccuracySec=1s
RandomizedDelaySec=0
Unit=timer-proof.service

[Install]
WantedBy=timers.target
EOF

sudo systemd-analyze verify \
  /etc/systemd/system/timer-proof.service \
  /etc/systemd/system/timer-proof.timer
sudo systemctl daemon-reload
sudo systemctl start timer-proof.service
sudo cat /var/lib/timer-proof/runs

Starting the service manually first isolates problems with permissions, command paths and the state directory. If a manual run fails, there is no need to investigate the calendar expression yet. DynamicUser and StateDirectory work together to manage the test service’s identity and writable directory, so there is no need to loosen directory permissions.

For production, use a verified absolute path to the script and define its exit codes explicitly. A failed business request that returns zero causes the service manager to record success. Conversely, a command returning zero does not prove that a report is complete.

Test catch-up after the timer has been stopped

There is no need to wait until the next day. Add a temporary override under /run to make the test timer fire once a minute, leaving the daily schedule in the permanent file unchanged.

sudo mkdir -p /run/systemd/system/timer-proof.timer.d
sudo tee /run/systemd/system/timer-proof.timer.d/acceptance.conf >/dev/null <<'EOF'
[Timer]
OnCalendar=
OnCalendar=*-*-* *:*:00 UTC
EOF

sudo systemctl daemon-reload
sudo systemctl start timer-proof.timer
sleep 70
sudo systemctl stop timer-proof.timer
sudo wc -l /var/lib/timer-proof/runs
sleep 130
sudo systemctl start timer-proof.timer
sleep 3
sudo wc -l /var/lib/timer-proof/runs
sudo systemctl list-timers --all timer-proof.timer

The empty OnCalendar= clears the original schedule; otherwise, both calendar expressions would apply. The first wait allows at least one actual trigger to occur. The timer then remains stopped across several minute boundaries.

Compare the line count after stopping the timer with the count after restarting it. Expect a catch-up run, not one additional entry for every minute missed while the timer was inactive. If the restart happens close to a regular minute boundary, subsequent scheduled triggers may also add entries. Use the log timestamps to interpret the result rather than comparing only the final line counts.

Also check LAST and NEXT in list-timers. Starting a persistent timer for the first time can itself cause a catch-up run, so immediate execution on the first start does not necessarily mean the expression is wrong. This experiment tests what happens after the timer has been stopped; it does not replace a server reboot test.

Introduce a controlled failure and retain execution evidence

A working scheduler does not mean the job succeeded. Stop the test timer, then use a temporary override to make the test service fail explicitly and check whether the status information reveals the problem.

sudo systemctl stop timer-proof.timer
sudo mkdir -p /run/systemd/system/timer-proof.service.d
sudo tee /run/systemd/system/timer-proof.service.d/failure.conf >/dev/null <<'EOF'
[Service]
ExecStart=
ExecStart=/usr/bin/false
EOF

sudo systemctl daemon-reload
sudo systemctl start timer-proof.service
sudo systemctl show timer-proof.service \
  -p Result -p ExecMainCode -p ExecMainStatus
sudo journalctl -u timer-proof.service -n 30 --no-pager

A nonzero return from start is expected here. If you include this step in an automated acceptance script, capture that exit status explicitly. The expected outcome is a failed service result, a nonzero main-process exit status and no new success timestamp in the record file.

A one-shot service normally returns to inactive after a successful run; that state alone should not trigger an alert. Alerts should consider at least the exit result, the most recent successful run and the business output. The service may have failed even while the timer remains active.

Long-running jobs have another important limitation: if a service with the same name is already running, subsequent timer triggers neither start another instance nor automatically queue a run. If every batch must be processed, the application must track pending intervals. The number of scheduler triggers cannot be treated as the number of completed runs.

Restore the production schedule and hand over the test record

Remove the failure override and the per-minute schedule, then reload systemd. Check the merged configuration after restoring it so that the test frequency does not accidentally reach production.

sudo rm /run/systemd/system/timer-proof.service.d/failure.conf
sudo rm /run/systemd/system/timer-proof.timer.d/acceptance.conf
sudo systemctl daemon-reload
sudo systemctl reset-failed timer-proof.service
sudo systemctl start timer-proof.service
sudo systemctl cat timer-proof.service timer-proof.timer
sudo systemctl enable --now timer-proof.timer
sudo systemctl list-timers --all timer-proof.timer

These commands leave the daily test probe in place. If this was a one-off experiment, stop and disable the timer, remove both test units and run daemon-reload. Archive the evidence before deleting state records; clearing the records is not a fix for a failure.

The final acceptance record should include the merged configuration, time synchronization status, the next five scheduled times, execution timestamps before and after the inactive period, the exit status from the controlled failure, and NEXT after restoration. If the job depends on a data directory or a remote service, also test the failure path for each unavailable dependency.

A scheduled job is ready for handover only when it does more than start on time: it must also be clear how missed work is recovered, how failures are detected and how repeated execution is prevented from producing incorrect results.

Frequently asked questions

Does Persistent=true replay every missed execution?

No. When an OnCalendar timer is activated after missing one or more scheduled events, it normally triggers one catch-up run. The application must track and process individual missing business periods.

Does an active timer mean the latest job succeeded?

No. It describes the scheduler state. Check Result and ExecMainStatus on the associated service, along with execution logs and the actual output.

Dedicated EPYC 7543P Server from $460.4/month

Choose from two ECC memory options. Confirm the configuration and amount due on the configuration page.