Skip to content

Instantly share code, notes, and snippets.

@MartinNowak
Last active August 28, 2023 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinNowak/928703623b1d0fbe57c06259255a288a to your computer and use it in GitHub Desktop.
Save MartinNowak/928703623b1d0fbe57c06259255a288a to your computer and use it in GitHub Desktop.
dnf-automatic restart hook
#!/usr/bin/env bash
set -ueEo pipefail
if ! dnf needs-restarting --reboothint; then
systemctl reboot --message='Rebooting after dnf-automatic updates'
fi
mapfile -t services < <(dnf needs-restarting --services)
if [[ "${#services[*]}" -ne 0 ]]; then
echo "Restarting ${services[*]}"
printf '%s\n' "${services[@]}" | xargs --no-run-if-empty --max-args=1 systemctl restart
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment