When you install certain updates, especially a kernel update in Ubuntu Desktop, you will get an indication that a reboot is required. But how about in Ubuntu Server? How do you know your Ubuntu requires reboot? This guide will show you how to know if your Ubuntu needs ta reboot.
Check MOTD
When you SSH to your Ubuntu, usually you will see the Message Of The Day (MOTD). By default, it usually shows a message if your Ubuntu requires reboot.
If your MOTD messages says:
*** System restart required ***
Then your Ubuntu needs a reboot.
Check /var/run/reboot-required
Run this in terminal console:
cat /var/run/reboot-required
Basically, you just need to check if the file /var/run/reboot-required has been created after updates, configuration changes or security updates to know if your Ubuntu needs reboot. If you need to check which installed packages need the reboot, then open the file /var/run/reboot-required.dpkgs
If the above file name of which packages produced the reboot notice doesn’t work for an installation, try changing the file name extension from .dpkgs to .pkgs (without the ‘d’)
Also read: Setup multi worksapces on Ubuntu 20.04/
Add Bash Script
You can create this bash script and extend it to send notification emails and run it daily from cron job.
#!/bin/bash
if [ -f /var/run/reboot-required ]; then
echo 'reboot required'
fi