新手问题 [Fixed] Mina 部署到 VPS 上后, Rails 无法启动

springwq · December 20, 2014 · Last by lips replied at March 20, 2015 · 3395 hits

使用 Mina 部署到 到 VPS 上一直报错,Passenger/Nginx 一直报错。查看了 Nginx 的 error.log, 也直接在 current 文件夹中运行 bundle exex rails s -e production 同样的报错。

在 Google 上搜了下,也没知道合适的解决方案。

但是,如果我直接 登录到 VPS 通过 Github 将项目 clone 下来,运行 rails s -e production, 就一切 OK.

current $ bundle exec rails s -e production
=> Booting WEBrick
=> Rails 4.1.8 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require': No such file to load -- pry (LoadError)
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
    from /home/steven/ps.stevenwu.cn/releases/6/app/controllers/queue_items_controller.rb:1:in `<top (required)>'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:348:in `require_or_load'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:307:in `depend_on'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /home/steven/ps.stevenwu.cn/releases/6/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/engine.rb:468:in `block (2 levels) in eager_load!'

Gemfile

source 'https://rubygems.org'

gem 'rails', '4.1.8'
gem 'pg'
gem 'sass-rails', '>= 3.2'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'haml-rails'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'bootstrap_form'    
gem 'bcrypt'
gem 'sidekiq'
gem 'sinatra', '>= 1.3.0', :require => nil
gem 'carrierwave'
gem 'mini_magick'
gem 'fog'

group :development do
  gem 'spring'
  gem 'pry'
  gem 'pry-remote'
  gem 'pry-nav'
  gem 'letter_opener'
  gem 'mina'
end

group :test, :development do
  gem 'fabrication'
  gem 'faker'
  gem 'capybara'
  gem 'capybara-webkit'
  gem 'launchy'
  gem 'rspec-rails'
end

group :test do
  gem "shoulda"
  gem "capybara-email"
end

group :production do
  gem 'rb-readline'
end

config/enviroment/production.rb

Rails.application.configure do

  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = true

  # Enable Rack::Cache to put a simple HTTP cache in front of your application
  # Add `rack-cache` to your Gemfile before enabling this.
  # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
  # config.action_dispatch.rack_cache = true

  # Disable Rails's static asset server (Apache or nginx will already do this).
  config.serve_static_assets = false

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false

  # Generate digests for assets URLs.
  config.assets.digest = true

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Specifies the header that your server uses for sending files.
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx

  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true

  # Set to :debug to see everything in the log.
  config.log_level = :info

  # Prepend all log lines with the following tags.
  # config.log_tags = [ :subdomain, :uuid ]

  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = "http://assets.example.com"

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  # config.action_mailer.raise_delivery_errors = false

  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  # the I18n.default_locale when a translation cannot be found).
  config.i18n.fallbacks = true

  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify

  # Disable automatic flushing of the log to improve performance.
  # config.autoflush_log = false

  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new

  # Do not dump schema after migrations.
  config.active_record.dump_schema_after_migration = false
end

config/deploy.rb

require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
# require 'mina/rvm'    # for rvm support. (http://rvm.io)

# Basic settings:
#   domain       - The hostname to SSH to.
#   deploy_to    - Path to deploy into.
#   repository   - Git repo to clone from. (needed by mina/git)
#   branch       - Branch name to deploy. (needed by mina/git)

set :rails_env, 'production'
set :domain, '106.185.29.213'
set :deploy_to, '/home/steven/ps.stevenwu.cn'
set :repository, 'https://github.com/springwq/photo_store.git'
set :branch, 'master'

# For system-wide RVM install.
#   set :rvm_path, '/usr/local/rvm/bin/rvm'

# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
# They will be linked in the 'deploy:link_shared_paths' step.
set :shared_paths, ['config/database.yml', 'log']

# Optional settings:
set :user, 'steven'    # Username in the server to SSH to.
set :ssh_options, '-A'
#   set :port, '30000'     # SSH port number.
#   set :forward_agent, true     # SSH forward_agent.

# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
task :environment do
  # If you're using rbenv, use this to load the rbenv environment.
  # Be sure to commit your .rbenv-version to your repository.
  invoke :'rbenv:load'
  # For those using RVM, use this to load an RVM version@gemset.
  # invoke :'rvm:use[ruby-1.9.3-p125@default]'
end

# Put any custom mkdir's in here for when `mina setup` is ran.
# For Rails apps, we'll make some of the shared paths that are shared between
# all releases.
task :setup => :environment do
  queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]

  queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
  queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]

  queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
  queue  %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml'."]
end

task :create_db do
  queue! %[rake db:create]
end

task :bundle_update do
  queue! %[bundle update]
end


desc "Deploys the current version to the server."
task :deploy => :environment do

  deploy do
    # Put things that will set up an empty directory into a fully set-up
    # instance of your project.
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :bundle_update
    invoke :'bundle:install'
    #invoke :create_db
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    to :launch do
      queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
      queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
    end
  end
end

# For help in making your deploy script, see the Mina documentation:
#
#  - http://nadarei.co/mina
#  - http://nadarei.co/mina/tasks
#  - http://nadarei.co/mina/settings
#  - http://nadarei.co/mina/helpers

gem 'pry' gem 'pry-remote' gem 'pry-nav'

把这三行从 :development 里面拿出来放到最外面试试看

#1 楼 @blacktulip 貌似 OK 了,我在 VPS 上直接 rails s -e production 没问题了,这是为什么呢? 现在切换到 Passenger/Nginx 后,403 了。汗。。。。

3 Floor has deleted

#2 楼 @springwq

你仔细看错误信息,No such file to load -- pry (LoadError) 说明服务器上没有 pry,为什么没有呢?因为你 gemfile 里面指明只有开发环境要装 pry,服务器是生产环境自然不会装。

至于为什么 403 这个就不清楚了,好好查查 log

#4 楼 @blacktulip 终于搞定了,nginx.conf 里面路径没写对。Big Thanks!

#2 楼 @springwq 你的 vps 内存多大?

7 Floor has deleted
8 Floor has deleted
9 Floor has deleted

#10 楼 @springwq 阿里云么?

You need to Sign in before reply, if you don't have an account, please Sign up first.