Deploying Sinatra app on Dreamhost/Passenger with custom gems

隐身守侯 提交于 2019-12-05 22:42:51
rogerdpack

I'd recommend creating your own gem path "somewhere" then adding it in your config.ru like:

ENV['GEM_PATH'] = xxx
Gem.clear_paths

then install your gems into that

Install Ruby gems on dreamhost

http://c.kat.pe/post/installing-ruby-gems-on-dreamhost/

Change config.ru (works for Sinatra 1.0)

require 'rubygems'

require 'vendor/sinatra/lib/sinatra.rb'

ENV['GEM_HOME'] = '/home/username/.gems'
ENV['GEM_PATH'] = '$GEM_HOME:/usr/lib/ruby/gems/1.8'
require 'rubygems'
Gem.clear_paths

disable :run, :reload

set :environment, :production

require 'yourapp'
run Sinatra::Application

Hope it helps someone.

I am using pony and a lot of other gems for my Sinatra. It should work well for you too. It's just those two lines (GEM_HOME and GEM_PATH) you have to add on your config.

Lemongrass

It took me ages to find that you can simply use "gem install sinatra" and gem will figure out (because the system directories are read-only) that you will need to use a local gem install directory. As of now, there seems to be no need to set any special environment at all. It figures out to use $HOME/.gem as the local gem path and everything just works. No need for require 'vendor/stuff' at all. I did find I had to add $HOME/.gem/ruby/1.8/bin to my path in order to execute binaries installed by gems.

Here's my config.ru (for Dreamhost)

## Passenger should set RACK_ENV for Sinatra
require 'test'
set :environment, :development
run Sinatra::Application

Later edit: This is all well and fine, but there remains the issue that Passenger can't find my gems when the job initially starts up.

include

My config.ru is just simple as:

require 'rubygems'
require 'vendor/sinatra/lib/sinatra.rb'
require 'app.rb'

and app.rb head:

require 'yaml'
require 'haml'
require 'ostruct'
require 'date'
require 'pp'

module FlytoFB
    log = File.new("sinatra.log", "a")
    STDOUT.reopen(log)
    STDERR.reopen(log)

    configure do

            enable :logging, :dump_errors
            set :app_file, __FILE__
            set :reload, true
            set :root, File.dirname(__FILE__)
            set :environment, :production
            set :env, :production
            set :run, false

            set :raise_errors, true
      set :public, 'public'

            error do
                    e = request.env['sinatra.error']
                    puts e.to_s
                    puts e.backtrace.join("\n")
                    "Application Error!"
            end

            not_found do
              "Page not found!"
      end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!