7

I have created a systemd user timer that expires daily, i.e. at midnight. The problem is that my computer is normally suspended at night. When I wake it up in the morning, I want the timer to trigger, but that doesn't happen. I discovered the Persistent option, but that only helps when the system is powered down, since it triggers expired timers when starting the services. Is there a solution to this other than e.g. running an hourly timer and saving a timestamp to a file somewhere?

Edit 2017-03-17: I'm using systemd 231 on ubuntu 16.10. What I want to is to run remind once a day, preferably when I wake up the computer in the morning.

0

2 Answers 2

3

One option you have is to set WakeSystem=true in your .timer file, which will wake the computer from suspend to run the job.

Then in the .service file that's run, you can add:

 ExecStopPost=sudo /bin/systemctl suspend

To re-resuspend the computer when the job is done running.

You'll also need to update /etc/sudoers to allow your user to run the above command without requiring a password.


A second option is to use one of the monotonic timers described in man systemd.timer like OnActiveSec=. These timers stop counting time when the computer is suspended. These allow you to express things like "Please backup my computer once every 8 hours that it is on". If your computer is normally on about 8 hours a day, this will roughly correspond to once per day. As you describe, your computer is frequently backed up around midnight anyway-- it's backed up when you first unsuspend it in the morning.


Third, did you confirm that Persistent= doesn't work with suspend as well when the machine is powered off?

2
  • 2
    We'll since I only want to use remind to show a desktop notification, it seems excessive to wake up the computer for that. Also, I would like to get the reminder first thing in the morning, so the OnActiveSec doesn't help with that. I confirmed that Persistent was enabled with systemctl show. I suspended the computer last evening and it hasn't fired today either. List-timers says n/a for last expiration time. Commented Mar 17, 2017 at 9:49
  • 1
    I think you should file a bug with systemd: github.com/systemd/systemd/issues I believe that either: 1. Persistent= should work through suspends or 2. the document for Persistent= should be updated to reflect that it doesn't "Persist" through suspends. Commented Mar 17, 2017 at 13:53
3

It seems there is no problem with the Persistent option and suspend. The problem seems to be that Persistent=true only works if the timer has had a chance to trigger at least once, i.e. if LAST is not n/a. But my computer is normally suspended at midnight, so the timer has never triggered.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .