Você pode tentar o seguinte script bash de esta resposta do ServerFault.
#!/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
Estou executando um servidor que roda no CentOS com cPanel (versão mais recente) e estou configurado para atualizar automaticamente usando o yum. Como ele precisa ser reinicializado para atualizar o kernel (e possivelmente outras coisas), fiquei me perguntando se existe alguma maneira de descobrir se uma reinicialização é necessária?
EDIT: O servidor é um VPS e está sendo executado no OpenVZ. Por causa da maneira como o OpenVZ funciona, não há /boot/vmlinuz e yum list installed kernel também não funciona.
Você pode tentar o seguinte script bash de esta resposta do ServerFault.
#!/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
Primeiro, imprimimos a versão do kernel em execução:
# uname -r
2.6.32-71.29.1.el6.i686
Ok, we have to patch:
# yum update kernel*
Grab the kexec tools:
# yum install kexec-tools
Now we get last installed kernel version release and put it on a var:
# latestkernel='ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | head -n1'
# echo $latestkernel
2.6.32-220.4.1.el6.i686
Now we need to load the new kernel version in memory:
# kexec -l /boot/vmlinuz-${latestkernel} --initrd=/boot/initramfs-${latestkernel}.img --append="'cat /proc/cmdline'"
Finally, we can issue a reset:
# kexec -e
..and.. wow, we lost the system! ..Well, not exactly.
The system will “restart without restarting”..something like a fast reboot, without performing BIOS checks (and you know how long can a full system restart last).
# uname -r
2.6.32-220.4.1.el6.i686
Funcionou!
Tags upgrade reboot centos linux-kernel