Last active
January 21, 2025 08:12
-
-
Save hkoba/e05c91ebdd4e2ffd1d79e78e76cf1ff5 to your computer and use it in GitHub Desktop.
systemd service and timer for scheduled reboot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Scheduled Reboot | |
[Service] | |
Type=simple | |
ExecStart=/usr/bin/systemctl --force reboot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Reboot Scheduling. | |
[Timer] | |
OnCalendar=*-*-* 01:30:00 | |
[Install] | |
WantedBy=multi-user.target |
If you want to store your custom services' files somewhere out of /etc/systemd/system
to make it easier to change the reboot hour for instance, you can use:
cd /correct/path/to/your/two/files
systemctl link ./sched-reboot.service
systemctl link ./sched-reboot.timer
So there are sym links in the place of the service and timer, directing to your files stored where you want.
Then, as Xeboc said above, don't forget to run:
systemctl daemon-reload
systemctl enable sched-reboot.timer
And finally you can check that your service and timer are correctly registered with:
systemctl status sched-reboot.timer
systemctl status sched-reboot.service
You should have Triggers: ● sched-reboot.service
on the timer, and TriggeredBy: ○ sched-reboot.timer
on the service.
If you don't need persistence, you can use systemd-run
to schedule the reboot fairly easily:
sudo systemd-run --on-calendar='2024-02-01 23:45 UTC' -- systemctl reboot --force
You also need to issue the start command to enable to timer schedule:
systemctl start sched-reboot.timer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@lwbt, @Xeboc, thank you for comments. Could you please, share a complete example, which follows your remarks?