This is a message which i get regular after updating my (ubuntu) linux server(s) and logging in later..
Quiet annoying for me, mostly when i login, i do not want the reboot the server, because it is in production. Even that the reboot time is short, i dont want to disrupt the processes.. So i wanted to scheduled the reboot when needed, instead of logging in on free hours. Actually that was quiet easy..
Step one:
Create a script that does trigger a restart when needed. But how do you check that? Actually very easy; when the file “/var/run/reboot-required” exists, you need to restart. So i created the following script: “reboot-when-required.sh”
#!/bin/bash
# To reboot @night add in root crontab:
# eg: sudo crontab -e:
# #Reboot when needed
# 0 4 * * * /home/<name>/bin/reboot-when-required.sh
#
if [ -f /var/run/reboot-required ]; then
echo "$(date +'%y%m%d %H:%M:%S') Reboot required; rebooting.." >> /home/<name>/bin/logs/reboot-required.log
/sbin/reboot
fi
This script is installed in de /home/<name>/bin folder, and a logs folder should also be created. It does the following:
- Check if file /var/run/reboot-required exists; when found:
- Add a line to the logging file
- Reboot the computer
Step two:
You need to add the following line(s) into the root crontab, als elevated rights are required:
#Reboot when needed
5 4 * * * /home/<name>/bin/reboot-when-required.sh
In the example this script is run daily @4:05 AM. You can change that to your requirements.