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