Use checkrestart if available for need-to-restart services

Checkrestart is faster than needrestart for that, so why not using it?
This commit is contained in:
Luc Didry 2016-08-02 09:08:57 +02:00
parent 354be0bc3e
commit 04dd8c42a7
2 changed files with 14 additions and 3 deletions

View File

@ -3,7 +3,7 @@
. /etc/update-motd.d/colors
if [[ -x /usr/sbin/needrestart ]]; then
n=$(DEBIAN_FRONTEND=noninteractive echo "" | needrestart -k -v -n 2>/dev/null | grep -c "Pending kernel upgrade\!")
n=$(DEBIAN_FRONTEND=noninteractive echo "" | /usr/sbin/needrestart -k -v -n 2>/dev/null | grep -c "Pending kernel upgrade\!")
if [[ $n -gt 0 ]]; then
printf $LIGHT_RED
printf " Pending kernel upgrade! "

View File

@ -2,8 +2,19 @@
. /etc/update-motd.d/colors
if [[ -x /usr/sbin/needrestart ]]; then
n=$(needrestart -l -v -n -r l 2>/dev/null | grep -c "Skipping")
if [[ -x /usr/sbin/checkrestart ]]; then
n=$(/usr/sbin/checkrestart | grep "Found .* processes using old versions of upgraded files")
re='Found (.*) processes using old versions of upgraded files'
if [[ $n =~ $re ]]; then
if [[ ${BASH_REMATCH[1]} -gt 0 ]]; then
printf $LIGHT_RED
printf " %s services need to be restarted.\n" "${BASH_REMATCH[1]}"
printf $NONE
printf " Use needrestart to list and restart them.\n\n"
fi
fi
elif [[ -x /usr/sbin/needrestart ]]; then
n=$(/usr/sbin/needrestart -l -v -n -r l 2>/dev/null | grep -c "Skipping")
if [[ $n -gt 0 ]]; then
printf $LIGHT_RED
printf " %s services need to be restarted.\n" $n