Skip to content

Commit

Permalink
Prefer loading Rack and Bundler from RubyGems instead of 'vendor_ruby'
Browse files Browse the repository at this point in the history
Closes GH-1478. Closes GH-1480.
  • Loading branch information
FooBarWidget committed Apr 17, 2015
1 parent c1a12c1 commit 4331c76
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -5,6 +5,7 @@ Release 5.0.7
* Request-specific environment variables are no longer cached. This fixes a number of issues, such as Shibboleth not working properly and conflicts between HTTPS and non-HTTPS virtual hosts. Closes GH-1472.
* Re-introduced signal catchers during shutdown, to allow clean shutdown in Foreman. Closes GH-1454.
* `passenger-status --show=xml` no longer outputs the non-XML header by default. This fixes a regression as reported in a comment in GH-1136.
* Passenger now prefers to load Rack and Bundler from RubyGems instead of from `vendor_ruby`. This solves some issues with Rack and Bundler on Debian systems. Closes GH-1480 and GH-1478.
* [Standalone] It is now possible to configure the Ruby, Node.js and Python executable to use in Passenger Standalone through the command line options --ruby, --nodejs and --python. Closes GH-1442.
* [Nginx] Introduces the `passenger_read_timeout` option for rare cases when server needs more than the default 10 minute timeout. Contributed by pkmiec. Closes [GH-PR-34](https://github.com/phusion/passenger/pull/34).
* [Nginx] The Nginx module now looks for index.html if the path ends in / so that it works intuitively, without needing to use try_files.
Expand Down
8 changes: 2 additions & 6 deletions helper-scripts/rack-loader.rb
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# encoding: binary
# Phusion Passenger - https://www.phusionpassenger.com/
# Copyright (c) 2013-2014 Phusion
# Copyright (c) 2013-2015 Phusion
#
# "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
#
Expand Down Expand Up @@ -94,12 +94,8 @@ def self.load_app
LoaderSharedHelpers.before_loading_app_code_step1('config.ru', options)
LoaderSharedHelpers.run_load_path_setup_code(options)
LoaderSharedHelpers.before_loading_app_code_step2(options)
LoaderSharedHelpers.activate_gem 'rack'

begin
require 'rubygems'
rescue LoadError
end
require 'rack'
rackup_file = options["startup_file"] || "config.ru"
rackup_code = ::File.open(rackup_file, 'rb') do |f|
f.read
Expand Down
6 changes: 1 addition & 5 deletions helper-scripts/rack-preloader.rb
Expand Up @@ -98,12 +98,8 @@ def self.preload_app
LoaderSharedHelpers.before_loading_app_code_step1('config.ru', options)
LoaderSharedHelpers.run_load_path_setup_code(options)
LoaderSharedHelpers.before_loading_app_code_step2(options)
LoaderSharedHelpers.activate_gem 'rack'

begin
require 'rubygems'
rescue LoadError
end
require 'rack'
rackup_file = options["startup_file"] || "config.ru"
rackup_code = ::File.open(rackup_file, 'rb') do |f|
f.read
Expand Down
26 changes: 23 additions & 3 deletions lib/phusion_passenger/loader_shared_helpers.rb
@@ -1,6 +1,6 @@
# encoding: binary
# Phusion Passenger - https://www.phusionpassenger.com/
# Copyright (c) 2011-2013 Phusion
# Copyright (c) 2011-2015 Phusion
#
# "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
#
Expand Down Expand Up @@ -274,8 +274,7 @@ def run_load_path_setup_code(options)
# there's always the load_path_setup_file option and
# setup_load_paths.rb.
running_bundler(options) do
require 'rubygems'
require 'bundler/setup'
activate_gem 'bundler', 'bundler/setup'
end
end

Expand Down Expand Up @@ -376,6 +375,27 @@ def after_handling_requests
PhusionPassenger.call_event(:stopping_worker_process)
end

# Activate a gem and require it. This method exists in order to load
# a library from RubyGems instead of from vendor_ruby. For example,
# on Debian systems, Rack may be installed from APT, but that is usually
# a very old version which we don't want. This method ensures that the
# RubyGems-installed version is loaded, not the the version in vendor_ruby.
# See the following threads for discussion:
# https://github.com/phusion/passenger/issues/1478
# https://github.com/phusion/passenger/issues/1480
def activate_gem(gem_name, library_name = nil)
if !defined?(::Gem)
begin
require 'rubygems'
rescue LoadError
end
end
if Kernel.respond_to?(:gem, true)
gem(gem_name)
end
require(library_name || gem_name)
end

private
def running_bundler(options)
yield
Expand Down

0 comments on commit 4331c76

Please sign in to comment.