How to run "bundle exec" from a specific version of Ruby using RVM when there is no shell environment

Good. I have a confession - I'm still running the massive FCGI setup (only a lot of configured servers). I am trying to adapt it to rvm. In fcgi settings, I can specify the command line command to execute for my application (Sinatra, Rack, Bundler, all this), and this is what I would do without rvm

"bin-path" => "bundle exec rackup", "bin-environment" => ( "RACK_ENV" => "development" ), 

Assuming my rack file is just config.ru. Now on my Mac it works:

 "bin-path" => env.HOME + "/.rvm/gems/ruby-1.9.2-p180/bin/bundle exec rackup " + CWD + "/config.ru", "bin-environment" => ( "BUNDLE_GEMFILE" => CWD + "/Gemfile", "RACK_ENV" => "development" ), 

but not on the server. When dispatchers start, they get a stripped-down env where the RVM shell bypass no longer works. I suppose I should use the wrapper option to make some kind of wrapper, but I really don't understand how this will ease my problem and which arguments to use. Does anyone have experience using certain ruby ​​and self-written binaries without loading the RVM shell?

PS To prevent off-topic responses, thanks, I don't need Ruby 1.8.7, Passenger or nginx.

+4
source share
4 answers

You can use rvm exec :

Like most rvm installation operations, exec allows you to execute commands against all installed rubies. Unlike others, there is a key difference - exec allows you to run any command (compared to a ruby ​​/ gem, etc.) , and if it runs against only one ruby, it executes the equivalent of exec (for example, there is no error message) after setting up the environment .

If the rvm is located on $PATH for your web server user, you can do:

 "bin-path" => "rvm 1.9.2-p180 exec bundle exec rackup" 
+3
source

EDIT: Turns out Jacob was right, sorry for the downside. I decided to expand this solution a bit.

I could, as it turned out, use the rvm binary now, but since it is installed by the user, it is not located on $ PATH on my laptop

 bigbuk:~ julik$ which rvm bigbuk:~ julik$ 

but it is on the server.

 [ julik@serveur ~]$ which rvm /usr/local/rvm/bin/rvm [ julik@serveur ~]$ 

That's what confused me. Only it should be called with an absolute path (since FCGI works without setting the PATH correctly). Se, then the binary path should be configured accordingly, AND Of course, rvm will set GEM_HOME and GEM_PATH correctly for us. The only thing you really need to install is BUNDLE_GEMFILE, because the Bundler cannot automatically determine this from the rackup file, and the cdd of the FCGI process is garbage.

 "bin-path" => "/usr/local/rvm/bin/rvm 1.9.2-p180 exec bundle exec rackup /home/user/websites/behandelaar-web/current/web-root/", "bin-environment" => ( "BUNDLE_GEMFILE" => "/home/user/websites/behandelaar-web/current/Gemfile", "RACK_ENV" => "production", ), 

However, having a specific shell script written in Ruby has some merit, since both the rawn and bundle packages are very bad with intermittent exceptions , and if they say there are problems with the FCGI stone itself (this was what I had - with processing of string bytes by 1.8), this exception will not be correctly pushed through this multi-level package of wrappers and The most insightful thing that you will see in error reports will be status-500 from your web server.

+1
source

You tried to configure system variables as follows:

 /etc/environment BUNDLE_GEMFILE=path_to_the_file RACK_ENV=production RUBY_VERSION='ruby-1.9.2-p180' GEM_PATH='$HOME/rvm/...' 

you can configure any types of rubygems (gem environment) and rvm at the system level, and not just for the user.

0
source

Ok rvm-shell seems to be the answer to the problem as it is an executable and not a shell function. It is important that this is so GET_HOME and GEM_PATH, though!

  "bin-path" => "/usr/local/rvm/gems/ruby-1.9.2-p180/bin/bundle2 /home/user/websites/behandelaar-web/current/web-root/config.ru", "bin-environment" => ( "BUNDLE_GEMFILE" => "/home/user/websites/behandelaar-web/current/Gemfile", "RACK_ENV" => "production", "GEM_HOME" =>"/usr/local/rvm/gems/ruby-1.9.2-p180", "GEM_PATH" =>"/usr/local/rvm/gems/ruby-1.9.2-p180:/usr/local/rvm/gems/ ruby-1.9.2-p180@global ", ), ), 

The "bundle2" script is a combination between bundle exec and rackup with the added bonus of decent error reports (since fcgi does not have STDERR and does not have STDOUT, and many elements in the chain swallow all possible exceptions that lead to failures).

 #!/usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby # # Generated Manually! begin require 'rubygems' version = ">= 0" if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then version = $1 ARGV.shift end gem 'bundler', version load Gem.bin_path('bundler', 'bundle', version) load Gem.bin_path('rack', 'rackup', version) rescue Exception => e File.open("/tmp/fcgrun-crash.log", "w") do | f | f.puts(ENV.inspect) f.puts(e.class.to_s) f.puts(e.message) f.puts(e.backtrace.join("\n")) end # and raise further raise e end 
0
source

All Articles