Skip to content

Commit

Permalink
Fail script on background process failure (#10062)
Browse files Browse the repository at this point in the history
add logic to exit if background process fails

Signed-off-by: Jesse Nelson <[email protected]>
  • Loading branch information
jnels124 authored Jan 8, 2025
1 parent 45e4e78 commit 38d240b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/runbook/scripts/restore-volume-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function replaceDisks() {
local snapshotFullName="projects/${GCP_SNAPSHOT_PROJECT}/global/snapshots/${snapshotName}"
log "Recreating disk ${diskName} in ${GCP_PROJECT} with snapshot ${snapshotName}"
gcloud compute disks delete "${diskName}" --project "${GCP_PROJECT}" --zone "${diskZone}" --quiet
gcloud compute disks create "${diskName}" --project "${GCP_PROJECT}" --zone "${diskZone}" --source-snapshot "${snapshotFullName}" --type=pd-balanced --quiet &
watchInBackground "$$" gcloud compute disks create "${diskName}" --project "${GCP_PROJECT}" --zone "${diskZone}" --source-snapshot "${snapshotFullName}" --type=pd-balanced --quiet &
done

log "Waiting for disks to be created"
Expand Down
15 changes: 15 additions & 0 deletions docs/runbook/scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
set -euo pipefail
shopt -s expand_aliases

function backgroundErrorHandler() {
log "Background command failure signalled. Exiting..."
trap - INT
wait
exit 1
}

trap backgroundErrorHandler INT

function watchInBackground() {
local -ir pid="$1"
shift
"$@" || kill -INT -- -"$pid"
}

function checkCitusMetadataSyncStatus() {
TIMEOUT_SECONDS=600
local namespace="${1}"
Expand Down
2 changes: 1 addition & 1 deletion docs/runbook/scripts/volume-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ do
SNAPSHOT_REGION=$(echo "${DISK_NODE_ID}" | cut -d '-' -f 2-3)
DISK_ZONE=$(echo "${DISK_NODE_ID}" | cut -d '-' -f 2-4)
log "Creating snapshot ${SNAPSHOT_NAME} for ${diskName} with ${SNAPSHOT_DESCRIPTION} in ${SNAPSHOT_REGION}"
gcloud compute snapshots create "${SNAPSHOT_NAME}" \
watchInBackground "$$" gcloud compute snapshots create "${SNAPSHOT_NAME}" \
--project="${GCP_PROJECT}" \
--source-disk="${diskName}" \
--source-disk-zone="${DISK_ZONE}" \
Expand Down

0 comments on commit 38d240b

Please sign in to comment.