@@ -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.
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
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
126131ulimit -n 65536
127132
128133echo " ═══════════════════════════════════════════════════════════════════════════════"
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: $* "
130135echo " ═══════════════════════════════════════════════════════════════════════════════"
131136# Execute the command passed to container
132137# Temporarily disable set -e so we can capture the exit code
133138set +e
134139" $@ "
135140exit_code=$?
141+ echo " Exit code: $exit_code "
142+ echo " Now exiting with exit code and jumping to cleanup trap..."
136143exit $exit_code
0 commit comments