• Home »
  • Insights »
  • 503 Service Unavailable Error After Switching Litespeed Rails Site From Production Mode To Staging Mode

503 Service Unavailable Error After Switching Litespeed Rails Site From Production Mode To Staging Mode

Earlier I switched one of the Litespeed web server virtual hosts from production mode to staging mode and after gracefully restarting rails was receiving a 503 Service Unavailable error. Initially I thought that maybe Litespeed had to be restarted completely instead of just a graceful restart but that produced the same results. Below I describe the errors including errors in the Litespeed logs as well as how to resolve the issue which ended up being a silly mistake on my part.

503 Service Unavailable Error After Switching Rails Site To Staging Mode:

503 Service Unavailable Error: Litespeed Rails Site Staging Mode

After receiving the above 503 service unavailable error after switching the rails environment mode I looked in the Litespeed logs to be pointed in the right direction. The below text was obtained from the Litespeed logs when attempting to connect to the rails site that was switched from a production environment to a staging environment.

Litespeed Stderr Log After Rails Site Switched To Staging Environment Mode:

2010-04-14 09:49:24.474 [STDERR] /home/web/site2/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:218:in `establish_connection': staging database is not configured (ActiveRecord::AdapterNotSpecified)
        from /home/web/site2/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:209:in `establish_connection'
        from ./config/../vendor/rails/railties/lib/initializer.rb:332:in `initialize_database'
        from ./config/../vendor/rails/railties/lib/initializer.rb:120:in `process'
        from ./config/../vendor/rails/railties/lib/initializer.rb:93:in `send'
        from ./config/../vendor/rails/railties/lib/initializer.rb:93:in `run'
        from ./config/environment.rb:16
        from /var/lsws/fcgi-bin/RailsRunner.rb:68:in `require'
        from /var/lsws/fcgi-bin/RailsRunner.rb:68

As seen in the above error the issue is database related. In this scenario we are using PostgreSQL for the database however the issue was not database specific and instead was a silly mistake of not including staging as an option in the database.yml file. Below I show the initial database.yml without the staging environment variable configured and then the updated database.yml file with the staging environment variable configured.

Ruby Project Without Staging Environment Set In database.yml File:

development:
    adapter: postgresql
    database: dbname
    username: dbuser
    password: dbpass
    host: localhost

production:
    adapter: postgresql
    database: dbname
    username: dbuser
    password: dbpass
    host: localhost

Ruby Project With Staging Environment Set In database.yml File:

development:
    adapter: postgresql
    database: dbname
    username: dbuser
    password: dbpass
    host: localhost

production:
    adapter: postgresql
    database: dbname
    username: dbuser
    password: dbpass
    host: localhost

staging:
    adapter: postgresql
    database: dbname
    username: dbuser
    password: dbpass
    host: localhost

This is why it is always good to include all three possible Rails environment modes in your database.yml file from the start. Just in case you change your Ruby/Rails project to run in a different environment mode such as development, staging, or production. So after adding the staging configuration to the database.yml file the site started working without issue.

Agile Web Development with Rails, Third Edition (Paperback)

By (author): Sam Ruby, Dave Thomas, David Heinemeier Hansson


List Price: $43.95 USD
New From: $2.42 USD In Stock
Used from: $0.01 USD In Stock

The Ruby Programming Language (Paperback)

By (author): David Flanagan, Yukihiro Matsumoto


List Price: $39.99 USD
New From: $20.79 USD In Stock
Used from: $7.04 USD In Stock

Share