hn=$(hostname -f)
source /a/bin/bash_unpublished/source-state
-l() {
- "$@" |& systemd-cat -t myupgrade
+myreboot() {
+ for x in {30..1}; do
+ echo "pid $$. unattended upgrade, rebooting in $((x*10)) seconds" | wall -n
+ sleep 10
+ done
+ for x in {30..1}; do
+ if ! fuser /var/lib/dpkg/lock &> /dev/null; then
+ echo "pid $$. unattended upgrade, rebooting now" | pee cat "wall -n"
+ /a/bin/ds/keyscript-on
+ /sbin/reboot
+ exit 0
+ fi
+ echo "pid $$. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall -n
+ sleep 10
+ done
+ echo "pid $$. dpkg locked for 5 minutes, automatic reboot failed" | pee cat "wall -n"
}
-## temporary
-case $HOSTNAME in
- kd)
- exit 0
- ;;
-esac
-if checkrestart -b /a/bin/ds/checkrestart-blacklist -p -t &>/dev/null; then
- exit 0
+if [[ $HOSTNAME != "$MAIL_HOST" ]]; then
+ ksta=$(needrestart -b | sed -n 's/NEEDRESTART-KSTA: *//p');
+ case $ksta in
+ 1) : ;;
+ [023]) myreboot ;;
+ *) err error: unknown kernel status ;;
+ esac
fi
-if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
- # no automatic reboot for this host, just make an alert
- checkrestart -b /a/bin/ds/checkrestart-blacklist -p 2>/dev/null ||:
- exit 0
-else
- l checkrestart -b /a/bin/ds/checkrestart-blacklist -p 2>/dev/null ||:
+# needsrestarts automatic restarts failed.
+if ! out=$(/sbin/needrestart -p 2>&1); then
+ e "$out"
fi
-
-for x in {30..1}; do
- echo "pid $$. unattended upgrade, rebooting in $((x*10)) seconds" | wall -n
- sleep 10
-done
-for x in {30..1}; do
- if ! fuser /var/lib/dpkg/lock &> /dev/null; then
- echo "pid $$. unattended upgrade, rebooting now" | pee cat "wall -n"
- /a/bin/ds/keyscript-on
- /sbin/reboot
- exit 0
- fi
- echo "pid $$. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall -n
- sleep 10
-done
-echo "pid $$. dpkg locked for 5 minutes, automatic reboot failed" | pee cat "wall -n"