'检测到意外的文件结尾'在Passenger下部署Rails应用程序到Dreamhost时

时间:2012-07-07 00:44:52

标签: ruby-on-rails capistrano passenger dreamhost

我对rails应用程序比较陌生,但我有一个在本地工作的rails应用程序,我正在尝试部署到DreamHost上的共享托管服务器。我已经关注了所有wiki和stackoverflow问题,但对此的答案仍然无法解决。

我正在与Capistrano一起部署,我已经解决了所有问题,以便成功部署工作。但是,当我去访问网站上不是静态资源的任何内容时,我会遇到“内部服务器错误”以及来自Passenger的错误:

Internal server error
Passenger encountered the following error:
The application spawner server exited unexpectedly: Unexpected end-of-file detected.

Exception class:
PhusionPassenger::Rack::ApplicationSpawner::Error
Backtrace:
#   File    Line    Location
0   /dh/passenger/lib/phusion_passenger/rack/application_spawner.rb 134 in `start'
1   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    253 in `spawn_rack_application'
2   /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb   132 in `lookup_or_add'
3   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    246 in `spawn_rack_application'
4   /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb   82  in `synchronize'
5   /dh/passenger/lib/phusion_passenger/abstract_server_collection.rb   79  in `synchronize'
6   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    244 in `spawn_rack_application'
7   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    137 in `spawn_application'
8   /dh/passenger/lib/phusion_passenger/spawn_manager.rb    275 in `handle_spawn_application'
9   /dh/passenger/lib/phusion_passenger/abstract_server.rb  357 in `__send__'
10  /dh/passenger/lib/phusion_passenger/abstract_server.rb  357 in `server_main_loop'
11  /dh/passenger/lib/phusion_passenger/abstract_server.rb  206 in `start_synchronously'
12  /dh/passenger/helper-scripts/passenger-spawn-server 99  

我可以通过SSH连接到服务器并手动运行'rails s'以使服务器在端口3000上运行,并且其中的所有内容都很有效。

这是我的environment.rb:

# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
LoLItemDb::Application.initialize!

# potential fix for Dreamhost shared resources
# from: http://stackoverflow.com/a/3214748/189292
require 'rubygems'
require 'rubygems/gem_runner'
ENV['GEM_PATH'] = '/home/gravitydev/ruby/gems:/usr/lib/ruby/gems/1.8'
Gem.clear_paths

deploy.rb:

user = "XXXXXXXXX"
domain = "XXXXXXXXX.com"
database = "mysql.XXXXXXXXX.com"

set :application, "XXXXXXXXX"
set :rails_env, "production"
set :use_sudo, false

# set rake to be verbose for capistrano
# http://stackoverflow.com/questions/7071126/how-can-i-run-rake-with-trace-within-capistrano
set :rake, "#{rake} --trace"

# here we set a custom paths to commands since on Dreamhost
# servers the user path is a bit different
set :bundle_cmd, "/home/#{user}/.gems/bin/bundle"
require 'bundler/capistrano'

# redirect path for whenever, and use bundler to execute it
set :whenever_command, "/home/#{user}/.gems/bin/bundle exec whenever"
require 'whenever/capistrano'

# configure credentials
set :user, user
set :password, "XXXXXXXXX"

# configure git
default_run_options[:pty] = true                          # Must be set for the password prompt
                                                          # from git to work
set :repository, "git@github.com:XXXXXXXXX/XXXXXXXXX.git"  # Your clone URL
set :deploy_to, "/home/#{user}/#{domain}"
set :scm, "git"
set :scm_passphrase, "XXXXXXXXX"                    # The deploy user's password
set :scm_verbose, true
set :git_shallow_clone, 1

# configure deploy location
set :deploy_to, "/home/#{user}/#{domain}"

# setup web server
server domain, :app, :web, :db, :primary => true
#server domain, :app, :web
#role :db, database, :primary => true

# for SSH
# see: http://wiki.dreamhost.com/Capistrano
set :chmod755, "app config db lib public vendor script script/* public/disp*"

# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"

# run the all "LoL" tasks to refresh the database
#after "deploy:restart", "lol:all"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# for Passenger
namespace :deploy do
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

和GEMFILE:     来源'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'bundler'
gem 'rake'
gem 'sqlite3'
gem 'haml'
gem 'nokogiri'
gem 'json'
gem 'whenever'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
gem 'mysql2'
gem 'rack'
gem 'RedCloth', '4.2.9'
gem 'jquery-rails'
gem 'capistrano'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

大多数帖子似乎都暗示了宝石的路径不正确,但我已经通过搜索Google和Dreamhost中的文档找到了我可以找到的所有配置更改。非常感谢任何帮助!

2 个答案:

答案 0 :(得分:4)

经过一段时间的讨论之后,有几件事让我找到了解决方案。首先,在部署到Dreamhost时,您需要覆盖config.ru中的GEM_HOME路径,如下所示:

# taken from https://discussion.dreamhost.com/thread-128599.html
ENV['GEM_HOME'] = '/home/USERNAME/.gems'
require 'rubygems'
Gem.clear_paths

此外,我阅读了abhas的评论,让我觉得我的Gemfile需要我不需要指定的宝石。基本上,我之前添加了它们来尝试模仿我的本地gem安装,但发现我并不需要它们。我的最终Gemfile看起来像这样:

source 'https://rubygems.org'

gem 'rails', '3.2.6'
gem 'bundler'
gem 'rake'
gem 'sqlite3'
gem 'haml'
gem 'nokogiri'
gem 'whenever'
gem 'mysql'
gem 'mysql2'
gem 'jquery-rails'
gem 'capistrano'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

在做出这些改变之后,乘客很高兴并且发现了所有需要的宝石!感谢abhas让我想到在正确的地区改变事物。

编辑:当StackOverflow允许我时,我会接受这个答案:)

答案 1 :(得分:1)

你的gemfile中的

改变了这个

gem 'RedCloth', :require => 'redcloth'

它可能有用