5

How can I reset the left time of a user systemd timer?

I have a user systemd service:

[Unit]
Description=Remind to a take break

[Service]
ExecStart=/opt/scripts/break_reminder
Environment=PATH=/sbin:/bin:/usr/bin:/usr/sbin:/opt/scripts

[Install]
WantedBy=default.target

and a user systemd timer

[Unit]
Description=Remind to a take break

[Timer]
OnStartupSec=0min
OnUnitActiveSec=30min

[Install]
WantedBy=timers.target

Edit: Restarting the timer both by restart and stop + start isn't reseting the left time.

$ systemctl --user status break_reminder.timer 
● break_reminder.timer - Remind to take break
     Loaded: loaded (/home/adam/.config/systemd/user/break_reminder.timer; enabled; vendor pr>
     Active: active (waiting) since Sun 2021-05-30 16:19:00 CEST; 3h 48min ago
    Trigger: Sun 2021-05-30 20:24:05 CEST; 16min left
   Triggers: ● break_reminder.service

May 30 16:19:00 archadam systemd[383]: Started Remind to take break.

$ systemctl --user restart break_reminder.timer
$ systemctl --user status break_reminder.timer 
● break_reminder.timer - Remind to take break
     Loaded: loaded (/home/adam/.config/systemd/user/break_reminder.timer; enabled; vendor pr>
     Active: active (waiting) since Sun 2021-05-30 20:07:24 CEST; 1s ago
    Trigger: Sun 2021-05-30 20:24:05 CEST; 16min left
   Triggers: ● break_reminder.service

May 30 20:07:24 archadam systemd[383]: Stopping Remind to take break.
May 30 20:07:24 archadam systemd[383]: Started Remind to take break.

$ systemctl --user stop break_reminder.timer  
$ systemctl --user status break_reminder.timer
○ break_reminder.timer - Remind to take break
     Loaded: loaded (/home/adam/.config/systemd/user/break_reminder.timer; enabled; vendor pr>
     Active: inactive (dead) since Sun 2021-05-30 20:07:32 CEST; 1s ago
    Trigger: n/a
   Triggers: ● break_reminder.service

May 30 20:07:24 archadam systemd[383]: Stopping Remind to take break.
May 30 20:07:24 archadam systemd[383]: Started Remind to take break.
May 30 20:07:32 archadam systemd[383]: break_reminder.timer: Deactivated successfully.
May 30 20:07:32 archadam systemd[383]: Stopped Remind to take break.

$ systemctl --user start break_reminder.timer 
$ systemctl --user status break_reminder.timer
● break_reminder.timer - Remind to take break
     Loaded: loaded (/home/adam/.config/systemd/user/break_reminder.timer; enabled; vendor pr>
     Active: active (waiting) since Sun 2021-05-30 20:07:39 CEST; 2s ago
    Trigger: Sun 2021-05-30 20:24:05 CEST; 16min left
   Triggers: ● break_reminder.service

May 30 20:07:39 archadam systemd[383]: Started Remind to take break.

2 Answers 2

1

OnUnitActiveSec binds to the last activation time of break_reminder.service.

OnUnitActiveSec=
Defines a timer relative to when the unit the timer unit is activating was last activated.

(systemd.timer manpage)

So to reset the left time on break_reminder.timer, you'd need to reset the last activation timestamp of break_reminder.service.

Unfortunately there doesn't seem to be a way to reset this timestamp except by actually starting the service unit. (systemctl set-property isn't able to change the timestamp and it is neither affected by systemctl reset-failed, systemctl clean nor by systemctl daemon-reexec).

1

Restart the service:

# systemctl restart break_reminder.timer

and see whether this works.

If it does not try force-restarting:

# systemctl stop break_reminder.timer
# systemctl start break_reminder.timer

and let us know.

1
  • It's not working. I added the info to my question.
    – LokiNaBoki
    May 30, 2021 at 18:13

You must log in to answer this question.

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