Last active
June 9, 2026 02:33
-
-
Save alexishida/6720921ff6e7b2a468cd7c181a40b65e to your computer and use it in GitHub Desktop.
Initial script for rails application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # Função para logging | |
| log() { | |
| echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | |
| } | |
| export RAILS_ENV="${RAILS_ENV:-production}" | |
| export PORT="${PORT:-3000}" | |
| log "Starting Rails app in ${RAILS_ENV} mode" | |
| cd /app | |
| # Espera o banco de dados ficar disponível | |
| if [ -n "$DATABASE_URL" ]; then | |
| log "Waiting for database..." | |
| until bundle exec rails db:version > /dev/null 2>&1; do | |
| log "Database not ready, waiting..." | |
| sleep 2 | |
| done | |
| log "Database is ready" | |
| fi | |
| # Setup do banco | |
| bundle exec rails db:prepare | |
| # Pula seeds em produção se já existirem dados | |
| if bundle exec rails db:version > /dev/null 2>&1 && \ | |
| [ "$(bundle exec rails runner 'puts User.count')" -eq 0 ]; then | |
| log "Seeding database..." | |
| bundle exec rails db:seed | |
| fi | |
| # Inicia Puma com healthcheck | |
| log "Starting Puma" | |
| exec bundle exec puma -C config/puma.rb -b "tcp://0.0.0.0:${PORT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment