···11+#!/bin/bash
22+33+# Check if Docker daemon is running
44+if ! docker info > /dev/null 2>&1; then
55+ echo "Error: Docker daemon is not running. Please start Docker and try again."
66+ exit 1
77+fi
88+99+# Check if the container is running
1010+if [ "$(docker ps -q -f name=annos-postgres)" ]; then
1111+ echo "Postgres container is already running."
1212+ DB_RUNNING=true
1313+else
1414+ echo "Starting Postgres container..."
1515+ npm run db:start
1616+ DB_RUNNING=false
1717+fi
1818+1919+# Trap SIGINT and SIGTERM to stop the DB on exit, only if we started it
2020+function cleanup {
2121+ if [ "$DB_RUNNING" = false ]; then
2222+ if [ "$(docker ps -q -f name=annos-postgres)" ]; then
2323+ echo "Stopping Postgres container..."
2424+ npm run db:stop
2525+ npm run db:remove
2626+ fi
2727+ fi
2828+}
2929+trap cleanup SIGINT SIGTERM
3030+3131+# Run the dev command
3232+npm run dev:inner
3333+3434+# Cleanup after dev command exits
3535+cleanup