【问题标题】:changing ruby versions with foreman与工头一起更改 ruby​​ 版本
【发布时间】:2015-04-19 14:16:53
【问题描述】:

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

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

在命令行上单独运行脚本可以,但在工头中运行则不行。

【问题讨论】:

    标签: ruby rvm foreman


    【解决方案1】:

    Foreman 旨在运行与单个应用程序相关的多个进程,而不是运行多个应用程序。您应该为每个应用设置一个单独的Procfile,并在运行工头之前切换到适当版本的 ruby​​。

    【讨论】:

    • 这是一个权威的答案吗?我有几个可以协同工作的小应用程序,将它们一起启动真的很棒。升级到其他 ruby​​ 版本后,我也遇到了这个问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-04
    • 2017-09-12
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多