简体   繁体   中英

changing ruby versions with foreman

I need to use foreman to run multiple Rails apps, which works fine for the Rails apps that can run on same Ruby version as foreman is using. However, I have an older Rails app that requires Ruby 1.8.6. I've tried a few tricks already with no success:

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

Error output:

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

I also tried setting a .ruby-version file in the directory. The "cannot load such file" error that follows is because the app is attempting to run on Ruby 2.x instead of 1.8.6, so I know the ruby environment isn't changing to 1.8.6 as desired.

UPDATE:

Looking into the "RVM is not a function" I learned that rvm runs in two modes and I needed to switch rvm to function mode within the script. So, I created a run_old_web_app.sh script with the following (and updated the Procfile to call the script):

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

However, this also does not work and produces the following:

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

Running the script on command-line by itself works, but running it within foreman does not.

Foreman is designed to run multiple processes related to a single application, not to run multiple applications. You should have a separate Procfile for each app, and switch into the appropriate version of ruby before running foreman.

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