I wasn’t entirely sure where to put this, so around the Water Cooler it goes for the moment
Originally I wrote this script when I had akmods installed and needed to let them rebuild before rebooting a machine. It will poll every 30 seconds to see if there are any inhibitor blocks still active, and then run the command specified.
This let me install updates, wait for blocks to be released (so akmods, backups etc), and then reboot. If there’s an error, the second half won’t run at all and so the dnf output would still be visible when I get back to the PC.
Hopefully this might help a few people who have caused themselves issues by rebooting too soon after DNF finishes running.
To use: Copy the text and paste into a new file using your editor of choice somewhere on your path (~/.local/bin/after-inhibitors for example), make it executable (e.g. chmod +x ~/.local/bin/after-inhibitors) and then run it as shown:
dnf upgrade -y && after-inhibitors reboot - run DNF upgrade (without confirmation, so don’t include the -y if you want it to prompt you first), and if it is successful wait for inhibitors to be released before running reboot
after-inhibitors umount /run/media/tom/usb - Wait for inhibitors to be released and then unmount a disk labelled ‘usb’. As this isn’t waiting for a specific command to finish, it doesn’t tell you anything about the success or failure of any other commands holding the blocks. Just that they’re not blocking any more.
If you run the command without any arguments, it will wait and then print a message to the terminal.
#!/bin/bash
COMMAND="$*"
COMMAND=${COMMAND:-echo 'Inhibitors released'}
IGNORE_PAT='WHO\|No inhibitors\|inhibitors listed\|^\s*$'
DELAY=30
echo "Waiting for inhibitors to be released. Polling every ${DELAY} seconds"
while (systemd-inhibit --list --mode=block|grep -v "${IGNORE_PAT}" >/dev/null);
do
sleep "${DELAY}";
done;
${COMMAND}
I’m not expecting to update this, but if I do it will probably be the gist on GitHub