1

On production server Passenger(4.0.0.rc6 + nginx) keeps requiring the :development group in Gemfile. After manually commenting them out from Gemfile the app runs fine. Otherwise, Passenger would fail on starting the app because of the missing gems.

I checked the error page, it seemed Passenger was running in production mode:

Environment (value of RAILS_ENV, RACK_ENV, WSGI_ENV and PASSENGER_ENV)
production

Below are sources of my simple app, am I missing any setting to have Passenger work? Thanks.

Here is my app.rb, a simple sinatra app.

require 'rubygems'
require 'sinatra'
get "/" do
   "Hello!"
end

I deploy it by vlad to production server. Here is the config/deploy.rb

require 'bundler/vlad'
set :application, "sinatratest"
set :domain, "server domain"
set :deploy_to, "path/on/server"
set :repository, "mygithub branch"

And my config.ru

require 'rubygems'
require 'sinatra'
require './app'
run Sinatra::Application

And Gemfile

source 'https://rubygems.org'
gem 'sinatra'
group :development do
    gem 'vlad', require: false
    gem 'vlad-git', require: false
end
hbaderts
  • 14,136
  • 4
  • 41
  • 48
Wen
  • 1,230
  • 1
  • 14
  • 28

2 Answers2

2

Answer to my own question:

See the vlad part in Bundler manual, require 'bundler/vlad' and create a new task which runs both vlad:update and vlad:bundle:install or insert vlad:bundle:install to the original vlad:update command.

If the server uses RVM then it needs to set the path of bundle explicitly either by source ~/.rvm/scripts/rvm in the vlad task or use the vlad-extra gem, see this post.

What I am doing to make it work:

In config/deploy.rb:

require 'bundler/vlad'
set :bundle_cmd, "source $HOME/.rvm/scripts/rvm && bundle" 

In Rakefile:

namespace :vlad do
  desc "Run vlad:update and vlad:bundle:install"
  task :deploy => %w[vlad:update vlad:bundle:install]
end

On local machine run rake vlad:deploy and it works.

Wen
  • 1,230
  • 1
  • 14
  • 28
0

I think the Problem is

require 'rubygems'

As I understand this means require all gems from Gemfile. For just require the Productiv gems with:

require 'rubygems'
require 'bundler/setup'

Source: http://gembundler.com/v1.3/rationale.html

Sir l33tname
  • 4,026
  • 6
  • 38
  • 49
  • 1
    Hi @sir-script, thanks for the suggestion. I tried it and it didn't fix my problem. But you are right that it is a bundler setting problem. I googled with fewer keywords (instead of those in this question's title and found a solution). From the [Passenger manual](http://www.modrails.com/documentation/Users%20guide%20Nginx.html#bundler_support), before loading the application Passenger runs `bundle.setup` which loads `Gemfile`. What I missed is to run `bundle install --without development test` on server. This step creates `.bundle/config` such that Passenger can load gems correctly. – Wen Apr 18 '13 at 15:17