kfan / rpms / kexec-tools

Forked from rpms/kexec-tools 3 years ago
Clone
1c97aee
#!/bin/bash
1c97aee
# This util helps to reduce the workload of kdump service restarting
1c97aee
# on udev event. When hotplugging memory / CPU, multiple udev
1c97aee
# events may be triggered concurrently, and obviously, we don't want
1c97aee
# to restart kdump service for each event.
1c97aee
1c97aee
# This script will be called by udev, and make sure kdump service is
1c97aee
# restart after all events we are watching are settled.
1c97aee
1c97aee
# On each call, this script will update try to aquire the $throttle_lock
1c97aee
# The first instance acquired the file lock will keep waiting for events
1c97aee
# to settle and then reload kdump. Other instances will just exit
1c97aee
# In this way, we can make sure kdump service is restarted immediately
1c97aee
# and for exactly once after udev events are settled.
1c97aee
1c97aee
throttle_lock="/var/lock/kdump-udev-throttle"
1c97aee
1c97aee
exec 9>$throttle_lock
1c97aee
if [ $? -ne 0 ]; then
1c97aee
        echo "Failed to create the lock file! Fallback to non-throttled kdump service restart"
1c97aee
        /bin/kdumpctl reload
1c97aee
        exit 1
1c97aee
fi
1c97aee
1c97aee
flock -n 9
1c97aee
if [ $? -ne 0 ]; then
1c97aee
        echo "Throttling kdump restart for concurrent udev event"
1c97aee
        exit 0
1c97aee
fi
1c97aee
1c97aee
# Wait for at least 1 second, at most 4 seconds for udev to settle
1c97aee
# Idealy we will have a less than 1 second lag between udev events settle
1c97aee
# and kdump reload
1c97aee
sleep 1 && udevadm settle --timeout 3
1c97aee
1c97aee
# Release the lock, /bin/kdumpctl will block and make the process
1c97aee
# holding two locks at the same time and we might miss some events
1c97aee
exec 9>&-
1c97aee
1c97aee
/bin/kdumpctl reload
1c97aee
1c97aee
exit 0