Search code examples
ruby-on-railsrubyapachedockerpassenger

docker apache passenger: error cannot load such file bundler/setup (LoadError)


I'm trying to build a docker-image with running apache (+passenger), rails and shibboleth.

Unfortunately I can't get apache + passenger running ... I appreciate every hint! Maybe it is a permission problem? Everything was installed as root, but obviously some processes are running as nobody (as shown in the error log).

My docker base-image is "ruby:2.0.0" (debian 8). In this image I installed apache2, apache2-threaded-dev, libapr1-dev, libaprutil1-dev via apt-get and passenger via 'gem install passenger -v 4.0.59'. After this I used passenger-install-apache2-module to install the module.

Here is the error log:

cannot load such file -- bundler/setup (LoadError)
  /usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  /usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:411:in `activate_gem'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:295:in `block in run_load_path_setup_code'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:416:in `running_bundler'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:294:in `run_load_path_setup_code'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:99:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:153:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'

Environment (value of RAILS_ENV, RACK_ENV, WSGI_ENV, NODE_ENV and PASSENGER_APP_ENV)
  development

Ruby interpreter command
  /usr/local/bin/ruby

User and groups
  uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)

Apache passenger.load:

LoadModule passenger_module /usr/local/bundle/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so

Apache passenger.conf:

IfModule mod_passenger.c>
  PassengerRoot /usr/local/bundle/gems/passenger-4.0.59
  PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>

And myapp.conf:

<VirtualHost *:80>
#ServerName yourserver.com

# Tell Apache and Passenger where your app's 'public' directory is
DocumentRoot /var/www/myapp/public

PassengerRuby /usr/local/bin/ruby
RailsEnv development

# Relax Apache security settings
<Directory /var/www/myapp/public>
  Allow from all
  Options -MultiViews
  # Uncomment this if you're on Apache >= 2.4:
  Require all granted
</Directory>

Installed versions:

apache2 -v
Server version: Apache/2.4.10 (Debian)

ruby -v      
ruby 2.0.0p645 (2015-04-13 revision 50299)

gem -v
2.0.14

rails -v
Rails 4.0.5

passenger-config validate-install says "Everything looks good". And 'passenger-status':

Version : 4.0.59                                                               
Date    : 2015-10-13 09:03:32 +0000                                            
Instance: 5578                                                                 
----------- General information -----------                                    
Max pool size : 6                                                              
Processes     : 0                                                              
Requests in top-level queue : 0                                                

----------- Application groups -----------                                     
/var/www/myapp#default:                                                        
  App root: /var/www/myapp                                                     
  Requests in queue: 0 

passenger-memory-stats:

Version: 4.0.59                                                             
Date   : 2015-10-13 09:05:31 +0000                                          

--------- Apache processes ---------                                        
PID   PPID  VMSize    Private  Name                                         
------------------------------------                                        
5578  1     83.2 MB   ?        /usr/sbin/apache2 -k start                   
5599  5578  363.5 MB  ?        /usr/sbin/apache2 -k start                   
5600  5578  491.5 MB  ?        /usr/sbin/apache2 -k start                   
### Processes: 3                                                            
### Total private dirty RSS: 0.00 MB (?)                                    


-------- Nginx processes --------                                           

### Processes: 0                                                            
### Total private dirty RSS: 0.00 MB                                        


---- Passenger processes -----                                              
PID   VMSize    Private  Name                                               
------------------------------                                              
5581  218.3 MB  ?        PassengerWatchdog                                  
5584  564.5 MB  ?        PassengerHelperAgent                               
5590  217.8 MB  ?        PassengerLoggingAgent                              
### Processes: 3                                                            
### Total private dirty RSS: 0.00 MB (?)

All running processes:

ps aux                                                                      
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND       
root         1  0.0  0.0  20300  1780 ?        Ss   08:47   0:00 bash          
root      6077  0.0  0.0  85160  3208 ?        Ss   09:11   0:00 /usr/sbin/apache2 -k start
root      6080  0.0  0.0 223500  2044 ?        Ssl  09:11   0:00 PassengerWatchdog
root      6083  0.0  0.0 578092  5556 ?        Sl   09:11   0:00 PassengerHelperAgent
nobody    6089  0.0  0.0 223028  5008 ?        Sl   09:11   0:00 PassengerLoggingAgent
www-data  6098  0.0  0.0 437788  5452 ?        Sl   09:11   0:00 /usr/sbin/apache2 -k start
www-data  6099  0.0  0.0 437780  5300 ?        Sl   09:11   0:00 /usr/sbin/apache2 -k start

EDIT After 2 days searching and trying I found a solution (right after I post here my question ...):

I have to put this into my apache virtual host configuration of my app:

SetEnv GEM_HOME /usr/local/bundle

This solution was postet on https://stackoverflow.com/a/19099768/4846489

I don't know why this is necessary, because I don't have a previous installation (as stated there). This is really strange, because this environment variable is already there if I login into my docker container (docker exec -u nobody)...


Solution

  • Setting GEM_HOME just patches over the real problem. This information here is your hint:

    User and groups:
    id=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
    

    Passenger is trying to run your app as the user 'nobody'. Most likely, this is not what you meant it to do. Your gem bundle is probably installed by a different user, and the 'nobody' user probably does not have access to that installed gem bundle.

    Why is Passenger running your app as 'nobody'? Because of user sandboxing rules, most likely caused by wrong permissions on your app. You should fix that.

    By the way, why are you building your own Docker image? Phusion provides its own passenger-docker base image.