Skip to content

Commit

Permalink
lmp: Push ostree repo with retries
Browse files Browse the repository at this point in the history
Run `fiopush` and `fiocheck` commands with up to 3 attempts.

Signed-off-by: Mike Sul <[email protected]>
  • Loading branch information
mike-sul committed Nov 4, 2024
1 parent 65a53fe commit 3363c14
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lmp/bb-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ DOCKER_MAX_CONCURRENT_DOWNLOADS="${DOCKER_MAX_CONCURRENT_DOWNLOADS-3}"
DOCKER_MAX_DOWNLOAD_ATTEMPTS="${DOCKER_MAX_DOWNLOAD_ATTEMPTS-5}"
MFGTOOL_FLASH_IMAGE="${MFGTOOL_FLASH_IMAGE-lmp-factory-image}"
USE_FIOTOOLS="${USE_FIOTOOLS-1}"
FIO_CHECK_CMD="${FIO_CHECK_CMD-/usr/bin/fiocheck}"
FIO_PUSH_CMD="${FIO_PUSH_CMD-/usr/bin/fiopush}"
FIO_PUSH_BIN="${FIO_PUSH_BIN-/usr/bin/fiopush}"
FIO_CHECK_BIN="${FIO_CHECK_BIN-/usr/bin/fiocheck}"
OSTREE_API_VERSION="${OSTREE_API_VERSION-v2}"
DEV_MODE="${DEV_MODE-0}"
BUILD_SDK="${BUILD_SDK-0}"
Expand Down Expand Up @@ -99,9 +99,11 @@ GARAGE_PUSH_RETRIES = "${GARAGE_PUSH_RETRIES-5}"
GARAGE_PUSH_RETRIES_SLEEP = "${GARAGE_PUSH_RETRIES_SLEEP-10}"
DOCKER_COMPOSE_APP = "${DOCKER_COMPOSE_APP}"
USE_FIOTOOLS = "${USE_FIOTOOLS}"
FIO_CHECK_CMD = "${FIO_CHECK_CMD}"
FIO_PUSH_CMD = "${FIO_PUSH_CMD}"
FIO_CHECK_PUSH = "${FIO_PUSH_CMD}"
FIO_CHECK_BIN = "${FIO_CHECK_BIN}"
FIO_PUSH_BIN = "${FIO_PUSH_BIN}"
FIO_CHECK_CMD = "${HERE}/fiocheck.sh"
FIO_PUSH_CMD = "${HERE}/fiopush.sh"
FIO_CHECK_PUSH = "${HERE}/fiopush.sh"
OSTREE_API_VERSION = "${OSTREE_API_VERSION}"
# Apps preloading params
Expand Down
7 changes: 7 additions & 0 deletions lmp/fiocheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

HERE=$(dirname $(readlink -f $0))
CHECK_BIN="${FIO_CHECK_BIN-/usr/bin/fiocheck}"

"${HERE}/run-with-retry.sh" "${CHECK_BIN}" $@

6 changes: 6 additions & 0 deletions lmp/fiopush.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

HERE=$(dirname $(readlink -f $0))
PUSH_BIN="${FIO_PUSH_BIN-/usr/bin/fiopush}"

"${HERE}/run-with-retry.sh" "${PUSH_BIN}" $@
34 changes: 34 additions & 0 deletions lmp/run-with-retry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

num_attempts=3

# Check if at least one argument is provided, the first argument is treated
# as the command to execute.
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <command> [args...]"
exit 1
fi

command=$1
shift # Shift out the command

# Track the attempt count
attempt=1

# Try to execute the command with retries
while [[ $attempt -le $num_attempts ]]; do
echo "Attempt $attempt/$num_attempts: Running '$command $@'"
$command "$@"

# Check if the command succeeded
if [[ $? -eq 0 ]]; then
echo "Command succeeded on attempt #$attempt"
exit 0
fi

echo "Command failed on attempt #$attempt. Retrying..."
attempt=$((attempt + 1))
done

echo "Command failed after $num_attempts attempts."
exit 1

0 comments on commit 3363c14

Please sign in to comment.