I recently applied a kernel patch (mix of Debian 10 and Ubuntu 18.04) using Ansible. I am trying to figure out a way to check if each machine being updated has been, or needs, a reboot. I've read that test -f /var/run/reboot-required is the official indicator however I've noticed this is not always true. Sometimes the file is there after a kernel upgrade, sometimes not. I'm not using LivePatch so any time there is a kernel update, I need to schedule reboots of all these systems.
In ansible, it was straightforward enough to test for the existence of the file above but since that's not consistent, I came up with the bash code below to test the running kernel version against the newest kernel image laying under /boot. This isn't exactly something you can plug right into ansible without a lot of hammering.
Is there a better way to determine if a reboot is needed?
if [[ $(uname -r) != .*"$(ls -1 /boot/vmlinuz* | sort -V | tail -1)"*. ]]; then
echo "Needs reboot. Running kernel $(uname -r) is older than $(ls -1 /boot/vmlinuz* | sort -u | tail -1)"
fi
/var/run/reboot*. There can be more than onefind /var/run | grep rebootcomes up empty. The running kernel on one system is4.15.0-166-genericand the latest is/boot/vmlinuz-4.15.0-167-generic. I've never known a kernel patch that didn't require a reboot so something is amiss with documentation or the system (/var/is only 18% capacity)find /var/run | grep reboot?