【问题标题】:How to update ENV variable on Passenger standalone restart如何在乘客独立重启时更新 ENV 变量
【发布时间】:2014-08-13 06:30:26
【问题描述】:

我正在使用 Capistrano 部署我的应用程序。应用程序在Passenger 上独立运行。当我重新部署应用程序时,Passenger 仍然使用旧版本中的 Gemfile,因为 BUNDLE_GEMFILE 环境变量尚未更新。

我应该将更新后的 Gemfile 路径放在哪里,以便乘客在重新启动时将其拾取?

服务器启动命令在 monit 中,我只是从 Capistrano 任务中调用 monit 脚本,除了重新启动,我只需触摸 restart.txt。

namespace :deploy do

  task :stop do
    run("sudo /usr/bin/monit stop my_app_#{rails_env}")
  end

  task :restart do
    run("cd #{current_path} && touch tmp/restart.txt")
  end

  task :start do
    run("sudo /usr/bin/monit start my_app_#{rails_env}")
  end

monit中的启动命令是:

start program = "/bin/su - app_user -l -c 'cd /home/app_user/current && bundle exec passenger start -d -p 8504 -e production  --pid-file=/home/app_user/current/tmp/pids/passenger.8504.pid  /home/app_user/current'"

我已经尝试将 BUNDLE_GEMFILE 添加到启动命令中,如下所示:

start program = "/bin/su - app_user -l -c 'cd /home/app_user/current && BUNDLE_GEMFILE=/home/app_user/current/Gemfile bundle exec passenger start -d -p 8504 -e production  --pid-file=/home/app_user/current/tmp/pids/passenger.8504.pid  /home/app_user/current'"

但它不起作用,因为路径 /home/app_user/current 是指向发布路径的符号链接,而是选择了该发布路径。

【问题讨论】:

  • 是否可以通过将启动命令移动到脚本文件中并在实际启动命令之前在文件中设置 BUNDLE_GEMFILE 变量来解决此问题?
  • 脚本文件可能无法解决它,因为重启不会使用脚本文件。
  • 你运行的是什么操作系统?

标签: ruby-on-rails bundler passenger monit


【解决方案1】:

简单的解决方案。

定义要在服务器启动命令中使用的 Gemfile。例如:

BUNDLE_GEMFILE=/home/app_user/current/Gemfile bundle exec passenger start -d -p 9999 -e production  --pid-file=/home/app_user/current/tmp/pids/passenger.9999.pid  /home/app_user/current

早期的解决方案(在 .profile 中设置 BUNDLE_GEMFILE 环境变量)并不好。当您部署应用程序的新版本并且捆绑包中有新 gem 时,迁移等将失败,因为它仍将使用 env 变量中定义的 Gemfile。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-05
    • 2011-12-11
    • 2015-12-11
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多