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