Michael K Madison
Michael K Madison

Reputation: 2209

load Rails environment for god monitor

I don't like hardcoding things that can be derived from the environment... and so in my god monitors I'd like to use ::Rails.root.to_s or ::Rails.env instead of ENV['RAILS_ENV'] || "production"

  1. Does it make sense to load Rails?
  2. How do I do it to merely get this functionality?

Upvotes: 0

Views: 467

Answers (1)

yfeldblum
yfeldblum

Reputation: 65445

You should not load the Rails application from your monitor.

Instead, you should establish required conventions.

  • The environment variables RACK_ENV or RAILS_ENV must be set correctly as environment variables, or there should be some other convention for the whole infrastructure stack knowing what the environment should be. In this example, every single piece of your infrastructure can use the magic formula ENV["RACK_ENV"] || ENV["RAILS_ENV"] || "development".

  • The application should be deployed to a well-known location that whole infrastructure stack knows about. For example, every single piece of your infrastructure can use the magic formula Pathname.new("/srv/apps").join(APPLICATION_NAME).join("current").to_s.

Upvotes: 3

Related Questions