X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;ds=sidebyside;f=filesystem%2Fusr%2Flocal%2Fbin%2Fmyupgrade;h=e5401dc836675ab54f9aafb31490ca5cf08ed7e7;hb=12cab163424e3a7b0815646d1d4407f9b5839bcb;hp=c358fcb5c59a8894e79df07837d9cda8417a0ee8;hpb=5e45ae077e790c0e798f09ffad8ecd3cb6c3bb28;p=distro-setup diff --git a/filesystem/usr/local/bin/myupgrade b/filesystem/usr/local/bin/myupgrade index c358fcb..e5401dc 100755 --- a/filesystem/usr/local/bin/myupgrade +++ b/filesystem/usr/local/bin/myupgrade @@ -19,41 +19,35 @@ err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; } 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"