Home > Blockchain >  apache, passenger/rails, ruby, redmine -- rails startup / gem path problem
apache, passenger/rails, ruby, redmine -- rails startup / gem path problem

Time:05-27

I am having a ruby gem path problem starting passenger on apache.

Environment:

  ubuntu-20
  passenger-6.0.14
  ruby-3.0.4

Ruby was installed system-wide using ruby-install, and is located at

  /opt/rubies/ruby-3.0.4

chruby is being used to set the ruby environment.
ruby apps and gems are (hopefully) installed on a per-user and per-app basis. In this case, redmine is the only app.

When I visit the newly-created redmine site, passenger fails to start rails because of a gem path problem:

  Raw Bundler exception:
  Bundler was unable to find one of the gems defined in the Gemfile
  Bundler tried to load the gems from #<struct Bundler::Settings::Path explicit_path=nil, system_path=false>
  Could not find rails-6.1.4.7, rouge-3.28.0, ...

The gems are in fact, present:

  $ cd ~
  $ find . | grep rails-6.1.4
  ./.gem/ruby/3.0.4/specifications/rails-6.1.4.7.gemspec
  ./.gem/ruby/3.0.4/cache/rails-6.1.4.7.gem
  ./.gem/ruby/3.0.4/gems/rails-6.1.4.7
  ./.gem/ruby/3.0.4/gems/rails-6.1.4.7/README.md

The apache ssl startup for the virtual host looks like:

<IfModule mod_passenger.c>
  PassengerRoot /home/test_user/.gem/ruby/3.0.4/gems/passenger-6.0.14
  PassengerDefaultRuby /opt/rubies/ruby-3.0.4/bin/ruby
</IfModule>
  ...
  Include rubies/test_user.include

and rubies/test_user.include has:

<Directory /var/www/html/issues-test>
    PassengerAppRoot /home/test_user/redmine_test
    PassengerAppEnv redmine_test
    PassengerAppGroupName redmine_test
    RailsBaseURI /issues-test
    PassengerUser test_user
    PassengerGroup test_user
    PassengerFriendlyErrorPages on
</Directory>

The gem environment for the user where redmine is installed:

  - RUBYGEMS VERSION: 3.2.33
  - RUBY VERSION: 3.0.4 (2022-04-12 patchlevel 208) [x86_64-linux]
  - INSTALLATION DIRECTORY: /home/test_user/.gem/ruby/3.0.4
  - USER INSTALLATION DIRECTORY: /home/test_user/.gem/ruby/3.0.0
  - RUBY EXECUTABLE: /opt/rubies/ruby-3.0.4/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /home/test_user/.gem/ruby/3.0.4/bin
  - SPEC CACHE DIRECTORY: /home/test_user/.local/share/gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /opt/rubies/ruby-3.0.4/etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-linux
  - GEM PATHS:
     - /home/test_user/.gem/ruby/3.0.4
     - /opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0
  - SHELL PATH:
     - /home/test_user/.gem/ruby/3.0.4/bin
     - /opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/bin
     - /opt/rubies/ruby-3.0.4/bin
     - /usr/local/sbin
     - /usr/local/bin
     - /usr/sbin
     - /usr/bin
     - /sbin
     - /bin
     - /snap/bin

Note that the shell PATH does not include the

/home/test_user/.gem/ruby/3.0.4/gems/

path; and the test_user.include shows no path to the gems for passenger.

I'm not clear on how ruby/passenger establishes the path for gems.
The passenger install was done from the user environment.

Note: I'm also unclear as to why the INSTALLATION DIRECTORY shows

/home/test_user/.gem/ruby/3.0.4

but the USER INSTALLATION DIRECTORY shows

/home/test_user/.gem/ruby/3.0.0.

(At some point I may have done ruby-install 3.0 and it installed 3.0.4). There is, however, no directory ~/.gem/ruby/3.0.0

CodePudding user response:

There were a couple of issues here. Thanks @Casper for some hints.

  1. Passenger must be installed system-wide, i.e., as root.
    It was installed as the redmine user, so had to be de-installed. Checking the passenger uninstall page for apache, it says "Remove the passenger files" and then details how to do that, assuming passenger was installed any way except from source.
    Unfortunately, I installed from source, as the regular repositories are way out of date. Uninstalling from source is non-trivial, as the passenger files are mixed in with the other application files and there is no easy way to find them all and differentiate. I ended up deleting the entire ruby / redmine environment for the user and starting over.

To install passenger as root, in a ruby-install/chruby environment:

sudo -i
cd /opt/rubies
source /usr/local/share/chruby/chruby.sh
chruby 3.0.4
gem install passenger
passenger-install-apache2-module
exit
  1. Once passenger was re-installed globally, attempting to set up redmine for a specific user still failed with the same error -- Bundler can't find any gems. I read several places that one should not have to set the GEM_PATH explicitly, as Passenger/Ruby/Bundler are supposed to be able to automatically find the gems they need if they are in a conventional place, but apparently not. My assumption was that since the passenger definition for the redmine app specified the user environment properly, they should be found. (It's not clear to me if this problem is specific to Passenger, an Apache2 installation, or Ruby/Bundler) The problem may be because I am using ruby-install and not rvm; passenger's docs seem to assume rvm is used as the installer. In any case, I had to explicitly set GEM_PATH in the apache2 configuration. The path is the one shown if "gem env GEM_PATH" is given from the user account. So for this case, in (file rubies/test_user.include above), add the line:

    SetEnv GEM_PATH /home/test_user/.gem/ruby/3.0.4/:/opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/

The complete apache2 config fragment looks like:

<Directory /var/www/html/issues-test>
    PassengerAppRoot /home/test_user/redmine_test
    PassengerAppEnv redmine_test
    PassengerAppGroupName redmine_test
    RailsBaseURI /issues-test
    PassengerUser test_user
    PassengerGroup test_user
    PassengerFriendlyErrorPages on
    SetEnv GEM_PATH /home/test_user/.gem/ruby/3.0.4/:/opt/rubies/ruby-3.0.4/lib/ruby/gems/3.0.0/
</Directory>
  • Related