【问题标题】:passing :rails_env in capistrano to chef/cookbook/monit/mongrel.conf将 capistrano 中的 :rails_env 传递给 chef/cookbook/monit/mongrel.conf
【发布时间】:2011-05-15 07:56:57
【问题描述】:

我们如何传递 :rails_env 变量,以便它识别我们所处的版本,即登台、生产、演示

我们正在尝试从 capistrano 中的 deploy.rb 获取 :rails_env 以传递给 cookbook,然后传递给 monit,然后为环境(demo..production)创建一个具有不同值的 mongrel.conf 文件。在 mongrel.erb 中,我们可以选择这个变量/参数并设置 RAILS_ENV=xxxx

在命令行中,想指定我们在做什么部署——cap chef:bootstrap production

这个“生产”在 deploy.rb 中设置 :rails_env

【问题讨论】:

    标签: capistrano mongrel monit chef-infra


    【解决方案1】:

    在运行脚本之前在 shell(命令行)中设置环境变量,让脚本获取它的值,即:

    export RAILS_ENV=production
    

    您可以在脚本中使用 $RAILS_ENV 访问 RAILS_ENV 的值。以下是有人在 Pivotal Labs 做类似事情的示例:

    http://pivotallabs.com/users/steve/blog/articles/1286-chef-solo-is-great-you-might-not-need-client-server-

    【讨论】:

    • 当 monit 运行 mongrel.conf 时,它不会获取任何环境变量。所以必须在 mongrel.conf 中设置 RAILS_ENV。这就是我们现在在 .conf 文件中的内容。启动程序 = "/usr/local/rvm/gems/ruby-1.8.7-p302/bin/mongrel_rails start -d -p 3000 -c /home/ubuntu/xx/current -e demo -P /home/ubuntu/ xx/current/log/nomad.3000.pid" 作为 uid ubuntu 和 gid ubuntu。我们希望根据 cap 命令行设置的内容来配置“演示”
    • 好的,所以在 deploy.rb 的某个地方你有 ":rails_env = demo",然后你可以让你的 Capistrano 任务执行 'run "export RAILS_ENV=#{​​rails_env}"' .. . 然后在你的 .conf 文件中你可以像这样选择环境变量: start program = "/usr/local/rvm/gems/ruby-1.8.7-p302/bin/mongrel_rails start -d -p 3000 -c / home/ubuntu/xx/current -e $RAILS_ENV -P /home/ubuntu/xx/current/log/nomad.3000.pid"
    • 轻微修正。命令行上的“cap chef:bootstrap rails_env=demo”会在 deploy.rb 中设置 :rails_env。我误解了你的问题。这有什么帮助吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多