These are the steps to create a scheduled reboot via systemd on Ubuntu.
Filenames and unit descriptions in the example are chosen arbitrarily and can be changed.
- Add a service unit that restarts the system. To do that, create a new file in
/etc/systemd/system/sched-reboot.service
and add the necessary configuration into it. The following service config will run a forced reboot through systemctl whenever started.[Unit] Description=Scheduled Reboot [Service] Type=oneshot ExecStart=/usr/bin/systemctl --force reboot
- Add a timer, that will start the reboot service on a schedule. Create a new file in
/etc/systemd/system/sched-reboot.timer
. The following config for the timer will run the reboot service daily at 4AM[Unit] Description=Reboot Scheduling [Timer] OnCalendar=*-*-* 4:00:00 [Install] WantedBy=multi-user.target
- (Optional) Run
systemd-analyze verify /etc/systemd/system/sched-reboot.*
to check for errors in the config files. If the return is empty, the files are in order. - Enable and start the timer by running
sudo systemctl enable sched-reboot.timer
andsudo systemctl start sched-reboot.timer
. - (Optional) Run
systemctl list-timers
to see all active timers as well as their next and last start information.
This is an older question, but it comes up as search result and does not contain any info about systemd, so I will add an example on how to do scheduled reboots with systemd. Filenames and unit descriptions in the example are chosen arbitrarily and can be changed.
- create new file:
/etc/systemd/system/sched-reboot.service
[Unit] Description=Scheduled Reboot
[Service] Type=oneshot ExecStart=/usr/bin/systemctl --force reboot
-
/etc/systemd/system/sched-reboot.timer
. [Unit] Description=Reboot Scheduling
[Timer] OnCalendar=*-*-* 4:00:00
[Install] WantedBy=multi-user.target
- (
- Enable and start the timer by running:
sudo systemctl enable sched-reboot.timer
sudo systemctl start sched-reboot.timer
.- (Optional) Run
systemctl list-timers
to see all active timers as well as their next and last start information.