aboutsummaryrefslogtreecommitdiffstats
path: root/roles/dnf_automatic/files/usr/local/sbin/dnf-auto-restart
blob: 76cc2d49d9e40b69267cfdb276153e1ef3163e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

set -Eeu -o pipefail
shopt -s lastpipe

if ! dnf needs-restarting --reboothint; then
  shutdown --reboot '+5' 'Rebooting to apply package upgrades'
  exit 0
fi

SERVICES=()

dnf needs-restarting --services | while read -r service; do
  if [[ $service = user@* ]]; then
    continue
  elif [ "$(systemctl show "$service" -P RefuseManualStop)" = yes ]; then
    continue
  else
    SERVICES+=("$service")
  fi
done

printf '\n'
if (( ${#SERVICES[@]} > 0 )); then
  echo 'restarting the following units:'
  printf '  * %s\n' "${SERVICES[@]}"
  systemctl restart "${SERVICES[@]}"
else
  echo 'All services are up to date.'
fi