Refactor how the 'trap' command is used to avoid double calls
in many files there was a secondary call to `trap` for the sole purpose of killing jornalctl (watching worker logs) so that GitLab CI doesn't hang. The issue with this is that sometimes the cleared the trap which invokes the cleanup() function without reinstating it again (not everywhere). Instead of doing this back-and-forth just make sure we don't leave any journalctl processes dangling in the background! NOTES: - for some scripts, mainly ostree- ones there was no cleanup trap present, but instead `trap` was configured inside the build_image() function. The trouble is that this function is executed multiple times and $WORKER_JOURNAL_PID changes value between these multiple executions. That's why these scripts introduce the cleanup_on_exit() function where we make sure to kill any possible dangling journalctl processes. - The name `cleanup_on_exit()` is chosed because these same scripts often have a helper function named clean_up() which is sometimes used to remove virtual machines and other artifacts between calls of build_image().
This commit is contained in:
parent
c534689d57
commit
85ce42570d
19 changed files with 110 additions and 83 deletions
|
|
@ -22,9 +22,14 @@ else
|
|||
fi
|
||||
|
||||
TEMPDIR=$(mktemp -d)
|
||||
# note: moved here to avoid undefined variable in cleanup()
|
||||
MINIO_CONTAINER_NAME="minio-server"
|
||||
function cleanup() {
|
||||
echo "== Script execution stopped or finished - Cleaning up =="
|
||||
sudo rm -rf "$TEMPDIR"
|
||||
|
||||
# Kill the MinIO server once we're done
|
||||
${CONTAINER_RUNTIME} kill ${MINIO_CONTAINER_NAME}
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
|
|
@ -60,7 +65,6 @@ fi
|
|||
mkdir "${MINIO_CONFIG_DIR}"
|
||||
$MC_CMD --version
|
||||
|
||||
MINIO_CONTAINER_NAME="minio-server"
|
||||
MINIO_ENDPOINT="http://localhost:9000"
|
||||
MINIO_ROOT_USER="X29DU5Q6C5NKDQ8PLGVT"
|
||||
MINIO_ROOT_PASSWORD=$(date +%s | sha256sum | base64 | head -c 32 ; echo)
|
||||
|
|
@ -88,8 +92,6 @@ ${CONTAINER_RUNTIME} run --rm -d \
|
|||
-e MINIO_ROOT_USER="${MINIO_ROOT_USER}" \
|
||||
-e MINIO_ROOT_PASSWORD="${MINIO_ROOT_PASSWORD}" \
|
||||
${CONTAINER_MINIO_SERVER} server /data
|
||||
# Kill the server once we're done
|
||||
trap '${CONTAINER_RUNTIME} kill ${MINIO_CONTAINER_NAME}' EXIT
|
||||
|
||||
# Configure the local server (retry until the service is up)
|
||||
MINIO_CONFIGURE_RETRY=0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue