简体   繁体   中英

Environment variable in unicorn script

I want to configure the worker processes depending on the environment. But how should I use the condition in unicorn script wrt environment variabes.

I have used following code but does not work -

if ENV['RAILS_ENV'] == "development"
      worker = 1
    elsif ENV['RAILS_ENV'] == "staging" || ENV['RAILS_ENV'] == "testing"
      worker = 2
    else
      worker = 16
    end

    worker_processes worker

If you see the code to define the Rails.env :

# File railties/lib/rails.rb, line 81
def env
  @_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end

Return "development" if ENV["RAILS_ENV"] and ENV["RACK_ENV"] are blank.

So you must use the Rails.env in your script or change it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM