1

Rails 3(Spree)アプリケーションがあり、開発では開始できますが、本番環境では開始できません。

私が実行するとbundle exec unicorn -c config/unicorn.rb -D -E development、すべてが機能します。

ただし、bundle exec unicorn -c config/unicorn.rb -D -E productionは次のように戻ります。

master failed to start, check stderr log for details

unicorn.stder.logファイルは次のとおりです。

I, [2012-06-04T17:31:54.497851 #10431]  INFO -- : listening on addr=/tmp/unicorn-uspatriottactical.socket fd=5
I, [2012-06-04T17:31:54.499222 #10431]  INFO -- : Refreshing Gem list
/var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require': can't convert Pathname into String (TypeError)
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:359:in `require_or_load'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:502:in `load_missing_constant'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:in `block in const_missing'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `each'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in `const_missing'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/bundler/gems/spree_related_products-72cbbfc9ed31/lib/spree_related_products.rb:17:in `block in <class:Engine>'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /var/rails/uspatriottactical/releases/20120604171150/config/environment.rb:5:in `<top (required)>'
        from config.ru:4:in `require'
        from config.ru:4:in `block in <main>'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
        from config.ru:1:in `new'
        from config.ru:1:in `<main>'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn.rb:44:in `eval'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn.rb:44:in `block in builder'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:696:in `call'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:696:in `build_app!'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:136:in `start'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/bin/unicorn:121:in `<top (required)>'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `load'
        from /var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>'

これはgemの問題のように思われるので、これが私のGemfileです。

source 'http://rubygems.org'

gem 'active_shipping',                  :git => 'git://github.com/Shopify/active_shipping.git'
gem 'carrierwave'
gem 'jquery-rails'
gem 'rails', '~> 3.2.0'
gem 'rmagick'
gem 'spree',                            :git => 'git://github.com/spree/spree', :branch => '1-1-stable'
gem 'spree_active_shipping',            :git => 'git://github.com/spree/spree_active_shipping.git'
gem 'spree_flexi_variants',             :git => 'git://github.com/jsqu99/spree_flexi_variants.git'
gem 'spree_reviews',                    :git => 'git://github.com/spree/spree_reviews.git'
gem 'spree_related_products',           :git => 'git://github.com/spree/spree_related_products.git'
gem 'spree_shipworks_api',              :path => 'spree_shipworks_api'
gem 'spree_amazon_fps',                 :path => 'spree_amazon_fps'
# gem 'spree_variant_options',            :git => 'git://github.com/citrus/spree_variant_options.git'
gem 'spree_videos',                     :git => 'git://github.com/iloveitaly/Spree-Videos.git'
gem 'spree_gateway',                    :git => 'git://github.com/spree/spree_gateway.git'
gem 'spree_paypal_express',             :git => 'git://github.com/spree/spree_paypal_express.git'
gem 'remit',                            :git => 'git://github.com/tylerhunt/remit.git'
#gem 'remit',                            :path => '../remit'
gem 'unicorn'

# temporary
gem 'sqlite3'
gem 'execjs'
gem 'therubyracer'


group :assets do
  gem 'coffee-rails', '~> 3.2.0'
  gem 'sass-rails',   '~> 3.2.0'
  gem 'uglifier', '>= 1.2.4'
end

group :console do
  gem 'awesome_print',                  :require => 'ap'
  gem 'hirb-unicode'
  gem 'wirb'
end

group :development, :test do
  gem 'capybara'
  gem 'factory_girl_rails'
  gem 'faker'
  gem 'mysql2'
  gem 'pry'
  gem 'rspec-rails'
  gem 'sunspot_rails', '~> 1.3.1'
  gem 'progress_bar', '0.4.0'
  gem 'sunspot_solr'
  gem "sunspot_with_kaminari", '~> 0.1'
  gem 'sqlite3'
  gem 'debugger'
end

group :development do
#  gem 'heroku'
  gem 'pry-rails'
end

group :production do

    gem 'capistrano'
    gem 'rvm-capistrano'


    gem 'mysql2'

    gem 'sunspot_rails', '~> 1.3.1'
    gem 'progress_bar', '0.4.0'
    gem 'sunspot_solr'
    gem "sunspot_with_kaminari", '~> 0.1'
end

# Used when running on Heroku
# group :deployment do
#   gem 'foreman'
#   gem 'pg'
#   gem 'thin'
# end

group :test do
  gem 'fakeweb'
  # Pretty printed test output
  gem 'turn', '~> 0.8.3',               :require => false
  gem 'vcr'
end

編集:これが私のunicorn.rbです

# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete documentation.

www_dir = "/var/rails/"
app_name = "uspatriottactical"

# Set environment to development unless something else is specified
#env = ENV["RAILS_ENV"] || "production"

# amount of unicorn workers to spin up
worker_processes 2

# Socket to bind to
listen "/tmp/unicorn-#{app_name}.socket"

preload_app true

# restarts workers that hang for 30 seconds
timeout 30

pid "/tmp/unicorn.#{app_name}.pid"



#if env == "production"
  user 'app_user', 'app_user' # 'user', 'group'

  working_directory "#{www_dir}#{app_name}/current"
  shared_path = "#{www_dir}#{app_name}/shared"

  stderr_path "#{shared_path}/log/unicorn.stderr.log"
  stdout_path "#{shared_path}/log/unicorn.stdout.log"
#end

before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
  end

  # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
  # immediately start loading up a new version of itself (loaded with a new
  # version of our app). When this new Unicorn is completely loaded
  # it will begin spawning workers. The first worker spawned will check to
  # see if an .oldbin pidfile exists. If so, this means we've just booted up
  # a new Unicorn and need to tell the old one that it can now die. To do so
  # we send it a QUIT.
  #
  # This enables 0 downtime deploys.
  old_pid = "/var/run/unicorn-#{app_name}.pid.oldbin"
  if File.exists?(old_pid) && server.pid != old_pid
    begin
      Process.kill("QUIT", File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
      # someone else did our job for us
    end
  end
end

after_fork do |server, worker|

  # Unicorn master loads the app then forks off workers - because of the way
  # Unix forking works, we need to make sure we aren't using any of the parent's
  # sockets, e.g. db connection (since "preload_app true")
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
  end

  # if preload_app is true, then you may also want to check and
  # restart any other shared sockets/descriptors such as Memcached,
  # and Redis.  TokyoCabinet file handles are safe to reuse
  # between any number of forked children (assuming your kernel
  # correctly implements pread()/pwrite() system calls)
end

編集:リクエストごと/var/rails/uspatriottactical/shared/bundle/ruby/1.9.1/gems/polyglot-0.3.3/lib/polyglot.rb

63行目にコメントしました

require 'pathname'

module Polyglot
  @registrations ||= {} # Guard against reloading
  @loaded ||= {}

  class PolyglotLoadError < LoadError; end

  class NestedLoadError < LoadError
    def initialize le
      @le = le
    end
    def reraise
      raise @le
    end
  end

  def self.register(extension, klass)
    extension = [extension] unless Array === extension
    extension.each{|e|
      @registrations[e] = klass
    }
  end

  def self.find(file, *options, &block)
    is_absolute = Pathname.new(file).absolute?
    (is_absolute ? [""] : $:).each{|lib|
      base = is_absolute ? "" : lib+File::SEPARATOR
      # In Windows, repeated SEPARATOR chars have a special meaning, avoid adding them
      matches = Dir["#{base}#{file}{,.#{@registrations.keys*',.'}}"]
      # Revisit: Should we do more do if more than one candidate found?
      $stderr.puts "Polyglot: found more than one candidate for #{file}: #{matches*", "}" if matches.size > 1
      if path = matches[0]
        return [ path, @registrations[path.gsub(/.*\./,'')]]
      end
    }
    return nil
  end

  def self.load(*a, &b)
    file = a[0].to_str
    return if @loaded[file] # Check for $: changes or file time changes and reload?
    begin
      source_file, loader = Polyglot.find(file, *a[1..-1], &b)
      if (loader)
        begin
          loader.load(source_file)
          @loaded[file] = true
        rescue LoadError => e
          raise Polyglot::NestedLoadError.new(e)
        end
      else
        raise PolyglotLoadError.new("Failed to load #{file} using extensions #{(@registrations.keys+["rb"]).sort*", "}")
      end
    end
  end
end

module Kernel
  alias polyglot_original_require require

  def require(*a, &b)
    polyglot_original_require(*a, &b) # <- line 63
  rescue LoadError => load_error
    begin
      Polyglot.load(*a, &b)
    rescue Polyglot::NestedLoadError => e
      e.reraise
    rescue LoadError
      # Raise the original exception, possibly a MissingSourceFile with a path
      raise load_error
    end
  end
end
4

1 に答える 1

1

ruby 1.9.3にアップグレードすると、この問題が修正されます。

詳細については、 github.com / cjheath / polyglot / issues/2を参照してください。

どうやら、RVMがインストールするruby1.9.1と1.9.2に問題があります。

于 2012-06-04T20:14:16.567 に答える