|
Server : Apache System : Linux ecngx264.inmotionhosting.com 4.18.0-553.77.1.lve.el8.x86_64 #1 SMP Wed Oct 8 14:21:00 UTC 2025 x86_64 User : lonias5 ( 3576) PHP Version : 7.3.33 Disable Function : NONE Directory : /proc/self/root/proc/thread-self/root/usr/local/bin/ |
Upload File : |
#!/bin/bash
###
### kexec wrapper for faster reboots.
###
version_sort() {
# tldr of this awk:
# if a digit in a version string isnt a number, assume .0.
# i.e. 4.18.0-553.69.1.lve > 4.18.0-553.lve.el8
awk -F'[-.]' '{ printf "%s.%s.%s.%s.%s.%s: %s\n",
$2, $3, $4, $5, $6 ~ /^[0-9]+$/ ? $6 : 0, $7 ~ /^[0-9]+$/ ? $7 : 0, $0
}' | sort -V | tail -1 | awk -F': ' '{print $2}'
}
kernel=""
for arg in "$@"; do
case "$arg" in
"latest" )
kernel="latest"
;;
"current" )
kernel="current"
;;
--help | -h)
echo "kreboot: Immediately sync then reinitialize the current or latest kernel using kexec instead of a hardware reboot"
echo "usage: kreboot [current|latest]"
echo "The purpose of this tool is to provide the option of faster recovery in reboots unrelated to hardware issues"
;;
* )
echo "usage: kreboot [current|latest]"
;;
esac
done
if [[ -z $kernel ]]; then
echo "Please select a kernel between \"current\" or \"latest\"."
else
echo "Loading $kernel kernel"
if [[ $kernel == "current" ]]; then
set -x
kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initramfs-$(uname -r).img --reuse-cmdline && sync && kexec -e
elif [[ $kernel == "latest" ]]; then
set -x
kexec -l $(find /boot/vmlinuz-* -not -name '*rescue*' | version_sort) --initrd=$(find /boot/initramfs-*.img -not -name "*kdump.img" | version_sort) --reuse-cmdline && sync && kexec -e
fi
fi