Do you really need to reboot your Linux server after an update?
For anyone who's ever maintained a linux server, you know that updates are easy, but after almost every one, it says:
*** System restart required ***
I started wondering if rebooting was really required, since sometimes you have mission-critical or otherwise busy servers, and rebooting is going to cause a problem for your users. But-- what if you need to reboot due to a security update or something like that?
Luckily, I found a simple shell script written by "Anton Lugovoi", which looks through your updates and classifies the need to restart as either low, medium, high, emergency, or critical.
I named the script reboot_required_check.sh and simply placed it in my home directory.
Note, you'll need to run as root.
#!/bin/bash
##################################
# Zabbix monitoring script
#
# Checking urgency in changelog
# for updates which require system restart
#
##################################
# Contact:
# anton dot lugovoi at yandex dot ru
##################################
# ChangeLog:
# 20151205 initial creation
# 20151208 check uniq packages only
##################################
echo "Checking how urgent a reboot is needed (takes up to 10 sec to run)..."
if [ -f /var/run/reboot-required.pkgs ]; then
while read pkg; do
tmp=`/usr/bin/apt-get changelog $pkg | \
/bin/grep -m1 -ioP '(?<=[Uu]rgency[=:])(low|medium|high|emergency|critical)' | \
tr '[:upper:]' '[:lower:]'`
if [ -n $tmp ]; then
if [ "$tmp" == "low" ] && \
[ "$urgency" != "medium" ] && \
[ "$urgency" != "high" ] && \
[ "$urgency" != "emergency" ] && \
[ "$urgency" != "critical" ]; then
urgency=low
elif [ "$tmp" == "medium" ] && \
[ "$urgency" != "high" ] && \
[ "$urgency" != "emergency" ] && \
[ "$urgency" != "critical" ]; then
urgency=medium
elif [ "$tmp" == "high" ] && \
[ "$urgency" != "emergency" ] && \
[ "$urgency" != "critical" ]; then
urgency=high
elif [ "$tmp" == "emergency" ] && \
[ "$urgency" != "critical" ]; then
urgency=emergency
elif [ "$tmp" == "critical" ]; then
urgency=critical
break
fi
fi
done < <(sort -u /run/reboot-required.pkgs)
else
urgency=none
fi
case "$urgency" in
none) urgency='none' ;;
low) urgency='low' ;;
medium) urgency='medium' ;;
high) urgency='high' ;;
emergency) urgency='emergency' ;;
critical) urgency='critical' ;;
*) urgency='asterisk?' ;;
esac
echo ""
echo " Reboot urgency = $urgency"
echo ""
echo " ('none', 'low', or 'medium' you probably do not need to reboot)"
echo ""
exit 0
Chmod the file so you can execute it:
chmod 755 reboot_required_check.sh (only need to do this once ;)
Example to run (if in your home dir).
sudo ~/reboot_required_check.sh
Hope this helps!
