[pmg-devel] [PATCH pmg-api master v1] systemd: fix report services failing if triggered to early by timers
Max R. Carrara
m.carrara at proxmox.com
Tue Sep 23 17:19:24 CEST 2025
Currently, the `pmgreport.service` and `pmgspamreport.service` units
might fail if their corresponding timers activate them too early.
To elaborate, both timers have `Persistent=true` in addition to their
`OnCalendar` option. `Persistent=true` means that the timer's service
unit will be triggered immediately when the timer is activated, but
only if it would have been triggered while the timer was inactive [0].
Since the timers are activated relatively early, they might trigger
their service units before postfix.service and postgresql.service have
come up, causing `pmgreport.service`, or `pmgspamreport.service`, or
both of them to fail.
Fix this by letting both service units wait until postfix and postgres
are up, which are necessary for the units to run successfully. Do this
by adding the `After` and `Wants` options for `postfix.service` and
`postgresql.service` to both service units.
Additional context:
While this is somewhat hard to encounter / debug under normal
circumstances, it is possible to make this race condition much more
apparent by adding an arbitrarily long delay to `postgresql.service`
and `postfix.service` by adding an override for each:
# systemctl edit postgresql.service
Then add the following:
[Service]
ExecStartPre=-sleep 15
Do the same for `postfix.service`.
Afterwards, change both timers to activate a few seconds after every
boot by adding an override for each:
# systemctl edit pmgreport.timer
Then add the following:
[Timer]
OnCalendar=
OnBootSec=5
Do the same for `pmgspamreport.timer`.
A reboot should now suffice to make the issue reproducible.
Conversely, the issue should not appear if this commit is applied.
(Also, don't forget to remove the overrides again after debugging.)
[0]: `man 5 systemd.timer`
Signed-off-by: Max R. Carrara <m.carrara at proxmox.com>
---
debian/pmgreport.service | 4 ++++
debian/pmgspamreport.service | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/debian/pmgreport.service b/debian/pmgreport.service
index 6b05213..89e25c7 100644
--- a/debian/pmgreport.service
+++ b/debian/pmgreport.service
@@ -1,6 +1,10 @@
[Unit]
Description=Send Daily System Report Mail
ConditionPathExists=/usr/bin/pmgreport
+After=postfix.service
+After=postgresql.service
+Wants=postfix.service
+Wants=postgresql.service
[Service]
Type=oneshot
diff --git a/debian/pmgspamreport.service b/debian/pmgspamreport.service
index a20214f..2b4f163 100644
--- a/debian/pmgspamreport.service
+++ b/debian/pmgspamreport.service
@@ -1,6 +1,10 @@
[Unit]
Description=Send Daily Spam Report Mails
ConditionPathExists=/usr/bin/pmgqm
+After=postfix.service
+After=postgresql.service
+Wants=postfix.service
+Wants=postgresql.service
[Service]
Type=oneshot
--
2.47.3
More information about the pmg-devel
mailing list