Market Data Service is a high-performance financial data API that provides comprehensive Symbol prices of different markets through both RESTful endpoints and real-time WebSocket connections.

entrypoint.sh 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. set -e
  3. echo "Starting Market Data Service API container..."
  4. # Wait for database to be ready
  5. if [ -f /usr/local/bin/wait-for-db.sh ]; then
  6. /usr/local/bin/wait-for-db.sh
  7. else
  8. echo "Waiting for database using pg_isready..."
  9. host="${DB_HOST:-db}"
  10. port="${DB_PORT:-5432}"
  11. user="${DB_USER:-postgres}"
  12. max_attempts=30
  13. attempt=0
  14. while [ $attempt -lt $max_attempts ]; do
  15. if PGPASSWORD="${DB_PASSWORD}" pg_isready -h "$host" -p "$port" -U "$user" >/dev/null 2>&1; then
  16. echo "Database is ready!"
  17. break
  18. fi
  19. attempt=$((attempt + 1))
  20. echo "Waiting for database... ($attempt/$max_attempts)"
  21. sleep 2
  22. done
  23. if [ $attempt -eq $max_attempts ]; then
  24. echo "ERROR: Database failed to become ready"
  25. exit 1
  26. fi
  27. fi
  28. # Sync models first to create tables (if they don't exist)
  29. echo "Syncing database models..."
  30. node -e "
  31. const { sequelize } = require('./src/models');
  32. sequelize.sync({ alter: true, force: false })
  33. .then(() => {
  34. console.log('Database models synced successfully.');
  35. process.exit(0);
  36. })
  37. .catch((error) => {
  38. console.error('Error syncing models:', error);
  39. process.exit(1);
  40. });
  41. " || {
  42. echo "WARNING: Model sync failed, continuing with migrations..."
  43. }
  44. # Run database migrations (if any exist, excluding archive folder)
  45. echo "Running database migrations (if any)..."
  46. if [ -d "migrations" ] && [ "$(find migrations -maxdepth 1 -name '*.js' -not -path '*/archive/*' 2>/dev/null | wc -l)" -gt 0 ]; then
  47. npx sequelize-cli db:migrate || {
  48. echo "WARNING: Database migration failed, but continuing..."
  49. }
  50. echo "Migrations completed"
  51. else
  52. echo "No migrations found, skipping migration step. Database schema created by model sync."
  53. fi
  54. # Start the application
  55. echo "Starting Node.js application..."
  56. exec "$@"