与领班改变红宝石版本

时间:2015-02-18 14:25:23

标签: ruby rvm foreman

我需要使用foreman来运行多个Rails应用程序,这适用于可以在工头使用的相同Ruby版本上运行的Rails应用程序。但是,我有一个较旧的Rails应用程序需要Ruby 1.8.6。我已经尝试了一些技巧但没有成功:

old_web_app: /bin/bash --login -c "cd ../2.1 && rvm use 1.8.6 && script/server"

错误输出:

06:14:03 old_web_app.1 | started with pid 36499
06:14:03 old_web_app.1 | RVM is not a function, selecting rubies with 'rvm use ...' will not work.
06:14:03 old_web_app.1 |
06:14:03 old_web_app.1 | You need to change your terminal emulator preferences to allow login shell.
06:14:03 old_web_app.1 | Sometimes it is required to use `/bin/bash --login` as the command.
06:14:03 old_web_app.1 | Please visit https://rvm.io/integration/gnome-terminal/ for an example.
06:14:03 old_web_app.1 |
06:14:03 old_web_app.1 | script/server:2:in `require': cannot load such file -- script/../config/boot (LoadError)
06:14:03 old_web_app.1 |    from script/server:2:in `<main>'
06:14:03 old_web_app.1 | exited with code 1
06:14:03 system        | sending SIGTERM to all processes

我还尝试在目录中设置.ruby-version文件。下面的“无法加载此类文件”错误是因为应用程序试图在Ruby 2.x而不是1.8.6上运行,所以我知道ruby环境没有根据需要更改为1.8.6。

更新:

查看“RVM不是函数”我了解到rvm以两种模式运行,我需要在脚本中将rvm切换到函数模式。因此,我使用以下内容创建了一个run_old_web_app.sh脚本(并更新了Procfile以调用脚本):

if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
  source "/usr/local/rvm/scripts/rvm"
else
  printf "ERROR: An RVM installation was not found.\n"
fi

cd "../2.1"
rvm use 1.8.6
script/server

但是,这也不起作用并产生以下内容:

07:06:55 old_web_app.1         | started with pid 38387
07:06:56 old_web_app.1         | Using /Users/mwlang/.rvm/gems/ruby-1.8.6-p420
07:06:56 old_web_app.1         | /Users/mwlang/.rvm/gems/ruby-1.8.6-p420@global/gems/executable-hooks-1.3.2/lib/executable-hooks/regenerate_binstubs_command.rb:89: warning: parenthesize argument(s) for future version
07:06:56 old_web_app.1         | /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/rubygems_integration.rb:366: warning: parenthesize argument(s) for future version
07:06:56 old_web_app.1         | /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/settings.rb:159:in `[]': odd number of arguments for Hash (ArgumentError)
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/settings.rb:159:in `load_config'
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/settings.rb:6:in `initialize'
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:213:in `new'
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:213:in `settings'
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:398:in `configure_gem_home_and_path'
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:90:in `configure'
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:151:in `definition'
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler.rb:116:in `setup'
07:06:56 old_web_app.1         |    from /Users/mwlang/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.2/lib/bundler/setup.rb:17
07:06:56 old_web_app.1         | exited with code 1
07:06:56 system            | sending SIGTERM to all processes

在命令行上运行脚本本身可行,但在foreman中运行它不会。

1 个答案:

答案 0 :(得分:0)

Foreman旨在运行与单个应用程序相关的多个进程,而不是运行多个应用程序。对于每个应用,您应该有一个单独的Procfile,并在运行领班之前切换到相应版本的ruby