I'd like to inhibit suspend while backups run on my laptop.  I'm scheduling those backups with a systemd timer[1] and service[2]. I've read that the default polkit policy only permits inhibiting suspend from within a login session, so I've also tried to add rules to allow the root user to inhibit suspend[3].  However, with all of those in place, I still get errors that I think indicate that the "systemd-inhibit" command is failing[4].

I'm running this on Fedora 33.  Has anyone successfully used systemd-inhibit from a systemd unit?


1:
# cat /usr/lib/systemd/system/run-borg.timer

[Unit]
Description=Periodic borg backup

[Timer]
OnCalendar=08..20/2:00
Persistent=true

[Install]
WantedBy=timers.target



2:
# cat /usr/lib/systemd/system/run-borg.service
[Unit]
Description=Run borg backup
RequiresMountsFor=/var/log
ConditionACPower=true

[Service]
Type=oneshot
ExecStart=/usr/bin/systemd-inhibit --who=borg-backup '--why=Backup in progress' --mode=block /root/run-borg



3:
# cat /etc/polkit-1/rules.d/root-inhibit-suspend.rules
polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.inhibit-block-shutdown" &&
        subject.isInGroup("root")) {
        return polkit.Result.YES;
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.inhibit-block-sleep" &&
        subject.isInGroup("root")) {
        return polkit.Result.YES;
    }
});

polkit.addRule(function(action, subject) {
    if (action.id == "org.freedesktop.login1.inhibit-block-idle" &&
        subject.isInGroup("root")) {
        return polkit.Result.YES;
    }
});



4:
Mar 21 18:00:41 vagabond systemd[1]: Starting Run borg backup...
Mar 21 18:00:41 vagabond systemd-inhibit[19767]: read: Connection reset by peer Mar 21 18:00:41 vagabond systemd-inhibit[19761]: /root/run-borg failed with exit status 1. Mar 21 18:00:41 vagabond systemd[1]: run-borg.service: Main process exited, code=exited, status=1/FAILURE Mar 21 18:00:41 vagabond systemd[1]: run-borg.service: Failed with result 'exit-code'.
Mar 21 18:00:41 vagabond systemd[1]: Failed to start Run borg backup.

_______________________________________________
users mailing list -- users@lists.fedoraproject.org
To unsubscribe send an email to users-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org
Do not reply to spam on the list, report it: 
https://pagure.io/fedora-infrastructure

Reply via email to