Skip to content

Commit 8d5c186

Browse files
committed
Fix(aws): Make exit status handling more bullet proof/simpler
1 parent 083c287 commit 8d5c186

2 files changed

Lines changed: 10 additions & 17 deletions

File tree

aws/docker_and_sync.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ cleanup() {
1919
echo "Cleanup stage of docker_and_sync.sh"
2020
echo "═══════════════════════════════════════════════════════════════════════════════"
2121
local exit_code=$?
22+
# Ensure cleanup failures do not clobber the original exit code
23+
set +e
2224
if [ -n "$(ls -A logs/ 2>/dev/null)" ]; then
2325
echo "Compressing rounds..."
2426
# Tar.gz all subfolders of any 'rounds' directory if we haven't done so.
@@ -60,9 +62,11 @@ PY
6062
docker stats --no-stream
6163
echo "Docker space usage:"
6264
docker system df
65+
echo "💾 Disk usage after job:"
66+
df -h
6367
echo "--------------------------------"
6468
echo "Last 100 lines of Docker logs"
65-
docker ps -aq | xargs -I {} sh -c 'logs=$(docker logs --tail 100 {} 2>&1); [ -n "$logs" ] && echo "=== {} ===" && echo "$logs"'
69+
docker ps -aq | xargs -r -I {} sh -c 'logs=$(docker logs --tail 100 {} 2>&1); [ -n "$logs" ] && echo "=== {} ===" && echo "$logs"'
6670
echo "--------------------------------"
6771
echo "Docker cleanup"
6872
docker system prune -af
@@ -71,6 +75,7 @@ PY
7175
echo "═══════════════════════════════════════════════════════════════════════════════"
7276
echo "✅ Wrapper script docker_and_sync.sh finished, exit code: $exit_code"
7377
echo "═══════════════════════════════════════════════════════════════════════════════"
78+
# This doesn't capture if things went wrong in this cleanup command itself, but that's ok.
7479
exit $exit_code
7580
}
7681

@@ -126,11 +131,13 @@ mkdir -p logs
126131
ulimit -n 65536
127132

128133
echo "═══════════════════════════════════════════════════════════════════════════════"
129-
echo "✅ Wrapper script docker_and_sync.sh pologue finished, executing user command: $*"
134+
echo "✅ Wrapper script docker_and_sync.sh prologue finished, executing user command: $*"
130135
echo "═══════════════════════════════════════════════════════════════════════════════"
131136
# Execute the command passed to container
132137
# Temporarily disable set -e so we can capture the exit code
133138
set +e
134139
"$@"
135140
exit_code=$?
141+
echo "Exit code: $exit_code"
142+
echo "Now exiting with exit code and jumping to cleanup trap..."
136143
exit $exit_code

aws/setup/docker/docker_entrypoint.sh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ echo "════════════════════════
66
echo "🚀 Hello from docker_entrypoint.sh"
77
echo "═══════════════════════════════════════════════════════════════════════════════"
88

9-
# Function to show disk usage on exit
10-
cleanup() {
11-
local exit_code=$?
12-
echo "💾 Disk usage after job:"
13-
df -h
14-
echo "═══════════════════════════════════════════════════════════════════════════════"
15-
echo "✅ docker_entrypoint.sh finished, exit code: $exit_code"
16-
echo "═══════════════════════════════════════════════════════════════════════════════"
17-
exit $exit_code
18-
}
19-
20-
# Set trap to always show disk usage on exit (normal exit, signals, errors)
21-
trap cleanup EXIT
22-
239
echo "📅 Container built at: $BUILD_TIMESTAMP"
2410
echo "🔄 Updating repository..."
2511

@@ -54,5 +40,5 @@ echo "════════════════════════
5440
echo "User provided command starting below:"
5541
echo "$@"
5642
echo "═══════════════════════════════════════════════════════════════════════════════"
57-
# Execute the remaining command arguments
43+
# Execute the remaining command arguments (container exits with same status)
5844
exec "$@"

0 commit comments

Comments
 (0)