1

I want to schedule a daily reboot on ubuntu core. There is no cron on ubuntu core.

But I can use systemd services

I have created a reboot.service and a reboot.timer

[Unit]
Description=reboot servuce
Requires=reboot.service

[Timer]
Unit=reboot.service
OnBootSec=2min
# every day at 4am
OnCalendar=*-*-* 4:00:00

[Install]
WantedBy=basic.target

But the problem this is executed on reboot. So there is reboot loop.

How do I avoid this.

I can write a reboot script that checks the last reboot time and only reboots if 24 hours has passed. Is there a better way?

Jake He
  • 2,417
  • 3
  • 29
  • 41

1 Answers1

0

From the man:

Timer unit files must include a [Timer] section, which carries information about the timer it defines. The options specific to the [Timer] section of timer units are the following:

OnActiveSec=, OnBootSec=, OnStartupSec=, OnUnitActiveSec=, OnUnitInactiveSec=

and further

OnCalendar= Defines realtime (i.e. wallclock) timers with calendar event expressions. See systemd.time(7) for more information on the syntax of calendar event expressions. Otherwise, the semantics are similar to OnActiveSec= and related settings.

Note that timers do not necessarily expire at the precise time configured >with this setting, as it is subject to the AccuracySec= setting below.

May be specified more than once, in which case the timer unit will trigger whenever any of the specified expressions elapse. Moreover calendar timers and monotonic timers (see above) may be combined within the same timer unit.

Thus your timer triggers every time 2 minutes have passed after a boot, thus most probably causing what is experienced as a loop.

llmabe
  • 1
  • 1