
You could check for the existence of /var/run/reboot-required just to see if a reboot is needed but it’s more useful to check the existence and contents of
/var/run/reboot-required.pkgs
This will show you a list of the packages that are requiring the reboot so you can triage how important it is.
This was found here: