Add trap for cleanup in e2e.sh script

- Added cleanup function to kill background processes
- Trap on EXIT ensures cleanup happens on normal exit, errors, or Ctrl+C
- Prevents orphaned backend/worker processes if script is interrupted
This commit is contained in:
counterweight 2025-12-21 23:17:17 +01:00
parent a8ad6e6384
commit b33e5e425a
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -3,6 +3,15 @@ set -e
cd "$(dirname "$0")/.."
# Cleanup function to kill background processes
cleanup() {
kill $BACKEND_PID 2>/dev/null || true
kill $WORKER_PID 2>/dev/null || true
}
# Ensure cleanup runs on exit (normal, error, or interrupt)
trap cleanup EXIT
# Load environment variables if .env exists
if [ -f .env ]; then
set -a
@ -49,9 +58,6 @@ else
fi
EXIT_CODE=$?
# Cleanup
kill $BACKEND_PID 2>/dev/null || true
kill $WORKER_PID 2>/dev/null || true
# Cleanup is handled by trap EXIT
exit $EXIT_CODE