Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to know if an upgrade is attended before upgrading

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
knoflook
Posts: 1
Joined: 2022-08-26 10:34

How to know if an upgrade is attended before upgrading

#1 Post by knoflook »

Hey,
I have a script which upgrades a bunch of servers. Sometimes, the script will hang because apt asks if it's safe to restart services in the middle of an upgrade. Due to the fiddly nature of running commands over ssh inside a bash script, the window doesn't render correctly. I need to know if an upgrade will show this window before it's ran. Basically I need to know in advance what will needrestart say after an upgrade. How can I do that? Or maybe there's a better way of running apt over ssh that will give me the window if it's needed?

Here's the script for reference. It needs to have a file named 'server-list' in the same directory, which contains hostnames of servers to upgrade, as well as properly structured 'pass' . Gum is a tool for reading from console.

Code: Select all

#!/bin/bash

set -e

function main() {
    if [[ ! -f "server-list" ]]; then
        echo "server-list is missing?"
        exit 1
    fi

    for i in $(cat ./server-list); do
      passcmd="pass show users/$REMOTE_USER/sudo/$i |"  # this is a hack to make it work with gum
      ./exp/bin/gum spin -s globe --title "updating package list for server $i..." $passcmd ssh $i 'sudo -p "" -S DEBIAN_FRONTEND=noninteractive apt-get update > /dev/null'

      echo "----------------------------------------------------------------"
      echo "server $i needs upgrades on the following packages:"
      pass show users/$REMOTE_USER/sudo/$i | \
        ssh $i 'sudo -p "" -S DEBIAN_FRONTEND=noninteractive apt list --upgradable'
      echo "----------------------------------------------------------------"
       
      ./exp/bin/gum confirm "Upgrade $i?" && pass show users/$REMOTE_USER/sudo/$i | \
             ssh $i 'sudo -p "" -S DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y'

      ./exp/bin/gum confirm --default=0 "Reboot $i?" && uselessVar=$(pass show users/$REMOTE_USER/sudo/$i | ssh -t $i 'sudo -S reboot; exit')

    done
}

main "$@"

Post Reply