Suavocado
Suavocado

Reputation: 969

How to check whether my Rails app is running with a dev or production environment while running

I'm running a rails app on a Centos 6.5 server with Passenger and Nginx. How can I check which environment it's running on without stopping it?

Upvotes: 6

Views: 4353

Answers (2)

sjagr
sjagr

Reputation: 16512

Your environment is found on Rails.env.

Loading development environment (Rails 4.2.3)
2.1.2 :001 > Rails.env
 => "development" 

You can also use the environment in a question format for conditionals:

2.1.2 :002 > Rails.env.production?
 => false 
2.1.2 :003 > Rails.env.pickle?
 => false 
2.1.2 :004 > Rails.env.development?
 => true 

Word of warning - this is if you want to program something within your code that checks the environment.

Upvotes: 8

Scott Jacobsen
Scott Jacobsen

Reputation: 985

Use the passenger-status command. For example, this shows me passenger is running the production environment (the first line under the Application groups heading):

(production-web) ubuntu@ip-10-0-3-146 ~% sudo passenger-status                                                              
Version : 5.0.15
Date    : 2015-08-20 17:40:24 +0000
Instance: lNNFwV1C (Apache/2.4.7 (Ubuntu) Phusion_Passenger/5.0.15)

----------- General information -----------
Max pool size : 12
App groups    : 1
Processes     : 6
Requests in top-level queue : 0

----------- Application groups -----------
/home/my-app/deploy/current (production):
  App root: /home/my-app/deploy/current
  Requests in queue: 0
  * PID: 11123   Sessions: 0       Processed: 12997   Uptime: 21h 14m 2s
    CPU: 0%      Memory  : 190M    Last used: 1s ago
  * PID: 11130   Sessions: 0       Processed: 140     Uptime: 21h 14m 2s
    CPU: 0%      Memory  : 153M    Last used: 9m 32s a
  * PID: 11137   Sessions: 0       Processed: 15      Uptime: 21h 14m 2s
    CPU: 0%      Memory  : 103M    Last used: 57m 54s
  * PID: 11146   Sessions: 0       Processed: 6       Uptime: 21h 14m 2s
    CPU: 0%      Memory  : 101M    Last used: 7h 47m 4
  * PID: 11153   Sessions: 0       Processed: 5       Uptime: 21h 14m 1s
    CPU: 0%      Memory  : 100M    Last used: 8h 42m 3
  * PID: 11160   Sessions: 0       Processed: 2       Uptime: 21h 14m 1s
    CPU: 0%      Memory  : 81M     Last used: 8h 42m 3

rails console is not reliable - it only tells you what environment the console is running under. Passenger may be configured to run in a different environment.

Upvotes: 10

Related Questions