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