Como posso verificar na linha de comando se uma reinicialização é necessária no RHEL ou no CentOS?

32

Estou usando o CentOS e o Red Hat Enterprise Linux em algumas máquinas sem a GUI. Como posso verificar se as atualizações instaladas recentemente exigem uma reinicialização? No Ubuntu, estou acostumado a verificar se /var/run/reboot-required está presente.

    
por Jim Hunziker 13.03.2010 / 12:52

9 respostas

20

link

Don't forget that you might need to reboot because of core library updates, at least if it is glibc. (And also, services may need to be restarted after updates).

If you install the yum-utils package, you can use a command called needs-restarting.

You can use it both for checking if a full reboot is required because of kernel or core libraries updates (using the -r option), or what services need to be restarted (using the -s option).

needs-restarting -r returns 0 if reboot is not needed, and 1 if it is, so it is perfect to use in a script.

An example:

root@server1:~> needs-restarting  -r ; echo $?
Core libraries or services have been updated:
  openssl-libs -> 1:1.0.1e-60.el7_3.1
  systemd -> 219-30.el7_3.9

Reboot is required to ensure that your system benefits from these updates.

More information:
https://access.redhat.com/solutions/27943
1
    
por 15.09.2017 / 13:27
28

Sobre a comparação de kernels instalados com a execução de um:

#!/bin/bash
LAST_KERNEL=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1)
CURRENT_KERNEL=$(uname -r)

test $LAST_KERNEL = $CURRENT_KERNEL || echo REBOOT

Espero que ajude!

    
por 15.09.2011 / 12:15
7

Você pode comparar a saída de uname -a com a lista de pacotes do kernel instalados

    
por 13.03.2010 / 13:14
6

uname -a vs. rpm -q kernel e needs-restarting de yum-utils

    
por 15.11.2016 / 18:30
5

Uma coisa que pode ser útil analisar em termos de "é necessário reinicializar" é se existem ou não arquivos removidos / substituídos pela atualização, mas para os quais os arquivos antigos ainda são carregados / usados por processos ativos.

Basicamente, quando o YUM atualiza um arquivo que está em uso por um processo, o próprio arquivo pode ter sido marcado para exclusão, mas o processo continua usando o arquivo antigo, pois possui um descritor de arquivo aberto no inode do arquivo antigo.

Um comando para obter uma contagem do número de arquivos antigos ainda em uso:

#lsof | grep "(path inode=.*)" | wc -l

Esse comando fornecerá uma contagem dos arquivos.

Use isso para ver quais arquivos estão realmente em uso:

#lsof | grep "(path inode=.*)"

Esse comando produzirá uma saída semelhante à seguinte em uma caixa atualizada pelo YUM:

COMMAND    PID   USER   FD      TYPE DEVICE SIZE/OFF   NODE NAME
sshd      3782   root  mem       REG   8,17          153427 /lib64/libcrypto.so.0.9.8e (path inode=153253)
mysqld    3883  mysql  mem       REG   8,17          153259 /lib64/libcrypt-2.5.so (path inode=153402)
mingetty  4107   root  mem       REG   8,17          153243 /lib64/libc-2.5.so (path inode=153222)
...
etc
    
por 19.06.2015 / 16:18
2

Verifique se o kernel em execução é o mais recente.

Se não estiver, verifique se o sistema foi reiniciado desde a instalação do kernel.

Se não foi, reinicie.

CURRENT_KERNEL="$(rpm -q kernel-$(uname -r))"
test -z "$CURRENT_KERNEL" && exit 0     # Current kernel is a custom kernel

LATEST_KERNEL="$(rpm -q kernel | tail -1)"
test -z "$LATEST_KERNEL" && exit 0      # No kernel package installed

LATEST_KERNEL_INSTALLTIME=$(rpm -q kernel --qf "%{INSTALLTIME}\n" | tail -1)
test -z "$LATEST_KERNEL_INSTALLTIME" && exit 1      # Error reading INSTALLTIME

test "$CURRENT_KERNEL" = "$LATEST_KERNEL" && exit 0 # Latest kernel running, no reboot needed

BOOTTIME="$(sed -n '/^btime /s///p' /proc/stat)"
test -z "$BOOTTIME" && exit 1           # Error reading BOOTTIME

test "$LATEST_KERNEL_INSTALLTIME" -lt "$BOOTTIME" && exit 1 # Latest kernel not running, but system was restarted already
                                        # User switched back to an old kernel?

echo reboot
    
por 10.03.2012 / 04:54
1

Eu sei que esta pergunta já foi respondida e que as pessoas postaram informações sobre a verificação de novos kernels, bem como arquivos excluídos, mas recentemente eu escrevi um script que verifica ambos. Se qualquer condição for detectada, a reinicialização será agendada para +30 minutos.

#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

NEW_KERN=0
DEAD_FILES=0

die () {
    printf "Error, exiting: "
    echo $@
    exit 1
}

for X in lsof wc column awk rpm sed head uname dd tr cut date logger shutdown; do
    which "${X}" >/dev/null 2>&1 || die "required application ${X} not found"
done

DATEY="$(date +%Y%m%d-%H%M%S)"
TMPFILE=/tmp/"$(dd if=/dev/urandom bs=1 count=256 2>/dev/null |tr -c -d '0-9a-f' |cut -c-7)"

[ $TMPFILE == "/tmp/" ] && die
echo "### Reboot automation notice: ${DATEY} ###" > "${TMPFILE}"
lsof +c0 -d DEL | grep -v '\s/SYSV' |awk 'NR==1 || !/dev\/zero/ {print $2,$1,$4,$NF}' | column -t >> "${TMPFILE}"

if [ $(cat ${TMPFILE} |wc -l) -gt 2 ]; then
    DEAD_FILES=1
else
    echo "### Reboot automation notice: ${DATEY} ###" > "${TMPFILE}"
fi

C_KERN="kernel-$(uname -r)"
A_KERN="$(rpm -q --last kernel |head -1 |sed 's|\s\+.*$||')"

[ $A_KERN != $C_KERN ] && NEW_KERN=1 && printf "Running $C_KERN, but $A_KERN available\n" >> "${TMPFILE}"

echo "### End of reboot automation notice: ${DATEY} ###" >> "${TMPFILE}"
if [[ $DEAD_FILES -eq 0 && $NEW_KERN -eq 0 ]]; then
    echo reboot not required
else
    logger -t rebooter -p auth.warning -f "${TMPFILE}"
    [ $DEAD_FILES -ne 0 ] && echo "   Processes running with broken links to executables,"
    [ $NEW_KERN -ne 0 ] && echo "   New kernel available,"
    echo Reboot is required
    shutdown -r +30 "System reboot is required.  To cancel use shutdown -c.  But don't because this system needs to be rebooted"
fi

[ -f "${TMPFILE}" ] && rm -f "${TMPFILE}"
    
por 15.11.2016 / 18:22
1

Aqui está a minha versão do código alexm. Você pode fazer isso:

LAST_KERNEL=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1)
 CURRENT_KERNEL=$(uname -r)

 if [ $LAST_KERNEL != $CURRENT_KERNEL ]
 then 
    echo "It is time to Reboot!"
 else 
    echo "There is nothing to do!"
 fi
    
por 22.08.2017 / 01:11
-5

install.log install.log.syslog yum.log você verifica este lugar o que tudo tem novo rpm tem instalação

    
por 16.07.2010 / 11:36