Files
update/software/upgrade-scripts/19-assert-docker-health.sh
Luis Eduardo Bonatti e93d1686f5 Move upgrade scripts from config repo to update repo
Since upgrade is responsibility of USM the upgrade scripts need
to be moved to this repo. This commit adds the upgrade-scripts
from config, note that the upgrade-scripts will still be located
under /usr/local/share/upgrade.d folder.
There's also a change in upgrade-scripts to use the log function
from this repo instead of controllerconfig one.
Also fix a log error in deploy scripts.

Test Plan:
PASS: Build-pkgs && build-image.
PASS: Upgrade from 24.09 to 25.09 in sx.
PASS: Install/bootstrap 25.09 in sx.
PASS: Check if /usr/local/share/upgrade.d have the same scripts.
PASS: Check scripts are logging accordingly.

Story: 2011357
Task: 52196

Change-Id: Iab5e6d6f0348f996daf0adb2447d22c4216e537f
Signed-off-by: Luis Eduardo Bonatti <luizeduardo.bonatti@windriver.com>
2025-05-22 13:17:48 +00:00

50 lines
1.3 KiB
Bash

#!/bin/bash
#
# Copyright (c) 2022-2025 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Sometimes docker will be in a bad state.
# Check for this and use some recovery logic to get it back to normal.
# Parameters for recovery logic
MAX_ATTEMPTS=5
TIME_STEP=6
# The migration scripts are passed these parameters:
NAME=$(basename $0)
FROM_RELEASE=$1
TO_RELEASE=$2
ACTION=$3
function log {
echo "$(date -Iseconds | cut -d'+' -f1): ${NAME}[$$]: INFO: $*" >> "/var/log/software.log" 2>&1
}
# Script start
if [[ "${ACTION}" != "activate" ]]; then
exit 0
fi
log "Starting docker health check script from release $FROM_RELEASE to $TO_RELEASE with action $ACTION"
# Docker is considered in a "bad state" if the service isn't active or
# if "/var/lib/docker/tmp" doesn't exist, as it won't be able to download images
attempts=0
while [ "$(systemctl is-active docker)" != "active" ] || [ ! -d "/var/lib/docker/tmp" ]; do
attempts=$(( $attempts + 1 ))
if [ "$attempts" -gt "$MAX_ATTEMPTS" ]; then
log "Could not fix docker service."
exit 0
fi
log "Docker in bad state. Restarting docker service. Attempt: $attempts/$MAX_ATTEMPTS"
systemctl restart docker
sleep $TIME_STEP
done
log "Docker service is active and healthy"
exit 0