Skip to content

prevent Automatic Service Restarts During Package Installation/Upgrade in SSH Sessions #9

@BaratovSokhibjon

Description

@BaratovSokhibjon

Problem Description

During package operations (apt-get upgrade, apt-get install, dpkg -i), the system attempts to restart kernel-level components and network services automatically. When connected via SSH, this behavior poses several critical risks:

  1. SSH Connection Loss: Network service restarts can drop the active SSH connection
  2. IP Address Changes: DHCP renewal during network restart may assign a different IP
  3. Server Inaccessibility: Loss of connection combined with IP change can make the server unreachable
  4. Failed Deployments: Interrupted scripts leave the system in an inconsistent state

This is particularly problematic in automated deployment scripts where losing SSH connectivity means the entire deployment fails mid-execution.

Current Implementation

We're currently using some mitigation strategies, but they're incomplete:

Example 1: apt-get upgrade

if [ "${UPGRADE_APT_PACKAGES}" = true ]; then
    echo "[INFO]: Upgrading packages..."
    ${_SUDO} DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get upgrade -y \
        -o Dpkg::Options::="--force-confdef" \
        -o Dpkg::Options::="--force-confold" \
        -o Acquire::Retries=3 || true
    echo "[OK]: Done."
fi

Example 2: dpkg -i

echo "[INFO]: Installing 'duf'..."
local _duf_version
_duf_version=$(curl -s https://api.github.com/repos/muesli/duf/releases/latest | grep "tag_name" | cut -d\" -f4 | sed 's/^v//')
rm -fv "duf_${_duf_version}_linux_${_ARCH_DPKG}.deb" || exit 2
wget "https://github.com/muesli/duf/releases/download/v${_duf_version}/duf_${_duf_version}_linux_${_ARCH_DPKG}.deb" || exit 2
${_SUDO} DEBIAN_FRONTEND=noninteractive dpkg -i "duf_${_duf_version}_linux_${_ARCH_DPKG}.deb" || exit 2
rm -fv "duf_${_duf_version}_linux_${_ARCH_DPKG}.deb" || exit 2
echo "[OK]: Done."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions