Search code examples
ruby-on-railsnginxraspberry-pipassenger

Error starting web application - Passenger, Rails, Raspberry PI


I have a ROR app (version 6.1.4.1) with Ruby 2.7.4 on a Raspberry Pi 4 with 4 GB RAM and a 32 GB SD card. I installed Passenger 6.0.12 using the tarball installation and am running it with nginx. passenger start in the app directory works successfully, but when I try running it as with nginx (/opt/nginx/sbin/nginx) on port 80, I get the above error when visiting the site.

I'm accessing the app via IP address, which is configured in the nginx.conf and the app is installed in /home/pi/src/bogie_can. There is a .bundle directory with a config file in the app directory, and that's where the gems are installed. I'm running the app in "development" mode, which is configured in the server section of the nginx.conf file using passenger_app_env.

The specific error is that the app cannot find racc-1.5.2. The Bundler info is #<struct Bundler::Settings::Path explicit_path="/home/pi/src/bogie_can/.bundle", system_path=false, default_install_uses_path=false>.. So, we note that the .bundle path is correct and in the .bundle/ruby/2.7.0/gems/ directory, racc-1.5.2 is indeed installed and owned by the user "pi".

I've cleared out old bundle installations and tried switching the app user from pi to root (which was nobody) and back. Also, I'm using rbenv, so I also ran rbenv rehash after the fresh bundle install. I've also carefully reviewed the "Detailed diagnostics" from the Passenger error page (which is super helpful!) and do not see anything that is obviously wrong.

Using the Passenger error page as a guide, it seems that:

  1. The gems are indeed installed as needed
  2. The user, either root or pi, have permissions to access the gems
  3. pi is a reasonable user to run the app
  4. The passenger_root and passenger_ruby are coming from the passenger-config about subcommands and are verified as well.

At this point, there must be some configuration I've overlooked or gotten wrong and I would greatly appreciate some questions and pointers.


Solution

  • I found the root cause of the problem.

    I had set passenger_ruby to the result of passenger-command about ruby-command, which gave me:

    passenger-config was invoked through the following Ruby interpreter:
      Command: /usr/bin/ruby2.7
      Version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm-linux-gnueabihf]
      To use in Apache: PassengerRuby /usr/bin/ruby2.7
      To use in Nginx : passenger_ruby /usr/bin/ruby2.7
      To use with Standalone: /usr/bin/ruby2.7 /usr/src/passenger-6.0.12/bin/passenger start
    
    The following Ruby interpreter was found first in $PATH:
      Command: /home/pi/.rbenv/shims/ruby
      Version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm-linux-gnueabihf]
      To use in Apache: PassengerRuby /home/pi/.rbenv/shims/ruby
      To use in Nginx : passenger_ruby /home/pi/.rbenv/shims/ruby
      To use with Standalone: /home/pi/.rbenv/shims/ruby /usr/src/passenger-6.0.12/bin/passenger start
    

    I was using /usr/bin/ruby2.7 and having the problem with racc not being found. I switched it to use the rbenv shim and Passenger was able to correctly find all the gems in the [APP_ROOT]/.bundle/ directory

    I also cleared out the default nginx installation, which was still trying to be started with nginx.service and then added my own /etc/init.d/nginx script and added it to the init.d database so that it now starts with the OS.