-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Is your feature request related to a problem? Please describe.
I want to run a daily backup job but only when
AssertACPower=true
AssertMemory= > 1000000000
First I added the above as conditions to the timer unit. But this causes the timer to stop and never come back in case the conditions fail. Then I moved the conditions to the service unit and also changed them to asserts.
Now the service fails if the laptop is not on ACPower when the timer triggers which is correct. But there is no way to configure a retry, e.g. 10 minutes later. So it could easily happen that the backup does not run for days because the laptop has not been on ACPower at the exact moments when the timer triggers.
I hoped, that Restart=on-failure would help, but it does not restart for an unmet condition or assert.
~/.config/systemd/user/backup-server-REDACTED.timer:
[Unit]
[Timer]
Unit=backup-server@REDACTED.service
OnCalendar=daily
AccuracySec=12h
Persistent=true
[Install]
WantedBy=timers.target
~/.config/systemd/user/backup-server@.service:
[Unit]
Description=Backup a server with rsync via ~/backups/backup.sh
AssertACPower=true
AssertMemory= > 1000000000
[Service]
Type=oneshot
ExecStart=%h/backups/backup.sh %i
Restart=on-failure
RestartSec=1m
Describe the solution you'd like
I want a oneshot service to run daily but only when the above conditions (ACPower, Memory) are met. I'm tolerant for the runtime to vary by 12h or even more.
I'm not experienced enough with systemd timers and service failure handling to suggest an implementation.
My initial thought was though that timers could have ConditionRetrySec parameter to retry a service after that interval.
Describe alternatives you've considered
I also tried OnUnitActiveSec and OnUnitInactiveSec with a short interval, but apparently a unit is configured to have been active, even if a condition failed.
The systemd version you checked that didn't have the feature you are asking for
systemd 250 (250.4-1~bpo11+1)
+PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT +GNUTLS -OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -BPF_FRAMEWORK -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified