Skip to content

Commit bcf7b36

Browse files
committed
fix: adjust healthcheck system
1 parent 0f99e88 commit bcf7b36

4 files changed

Lines changed: 43 additions & 4 deletions

File tree

Dockerfile.production

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ RUN mkdir -p /app/tmp/pids /app/tmp/cache /app/tmp/sockets /app/log && \
7777
USER rails:rails
7878

7979
# Expose port (Railway sets PORT=8080 by default)
80-
EXPOSE 3000
80+
EXPOSE 8080
8181

8282
# Health check (uses PORT env variable to match runtime configuration)
83-
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
84-
CMD curl -f http://localhost:${PORT:-3000}/up || exit 1
83+
# Note: Railway has its own health check system, but this is useful for local testing
84+
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
85+
CMD curl -f http://localhost:${PORT:-8080}/up || exit 1
8586

8687
# Entry point for database migration
8788
COPY --chown=rails:rails deploy/scripts/docker-entrypoint.sh /usr/local/bin/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
class HealthController < ActionController::API
4+
# Simple health check that doesn't check database
5+
def index
6+
render json: {
7+
status: 'ok',
8+
timestamp: Time.current.iso8601,
9+
environment: Rails.env
10+
}
11+
end
12+
13+
# Detailed health check with database verification
14+
def show
15+
database_status = check_database
16+
17+
render json: {
18+
status: database_status ? 'ok' : 'degraded',
19+
timestamp: Time.current.iso8601,
20+
environment: Rails.env,
21+
database: database_status ? 'connected' : 'disconnected'
22+
}, status: database_status ? :ok : :service_unavailable
23+
end
24+
25+
private
26+
27+
def check_database
28+
ActiveRecord::Base.connection.execute('SELECT 1')
29+
true
30+
rescue StandardError => e
31+
Rails.logger.error "Health check database error: #{e.message}"
32+
false
33+
end
34+
end

config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
# Health check endpoints
99
get 'up' => 'rails/health#show', as: :rails_health_check
10-
get 'health' => 'rails/health#show'
10+
get 'health' => 'health#index' # Simple health without DB check
11+
get 'health/detailed' => 'health#show' # Detailed health with DB check
1112

1213
# SEO - Sitemap
1314
get 'sitemap.xml', to: 'sitemap#index', defaults: { format: 'xml' }

deploy/scripts/docker-entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ fi
4949

5050
# Skip preload in production - Puma will handle it
5151
echo "[4/4] Starting application server..." >&2
52+
echo " → Port: ${PORT:-3000}" >&2
53+
echo " → Environment: ${RAILS_ENV:-development}" >&2
54+
echo " → Workers: ${WEB_CONCURRENCY:-2}" >&2
5255
echo "========================================" >&2
5356

5457
# Execute the main command

0 commit comments

Comments
 (0)