dispatch.fcgi for Rails 4 FCGI :: Stream :: Dreamhost中的错误

时间:2013-11-26 17:52:31

标签: ruby-on-rails imagemagick paperclip dreamhost fastcgi

我一直在使用Rails 4(安装在用户空间中)与Ruby 2.0和FastCGI来运行Rails应用程序,该应用程序上传包含多个图像的ZIP文件。使用Gem Paperclip管理上传并生成缩略图并插入水印。

zip文件上传得很好,它处理文件解压缩图像并创建新的Item模型以插入到数据库中,但它会在某个时刻挂起并丢弃错误:

    %%%%%%%%%%%About to process sites/thisite/releases/20131125055016/tmp/_RH75239.jpg
Command :: file -b --mime 'sites/thisite/releases/20131125055016/tmp/_RH75239.jpg'
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/_RH7523920131124-16069-ctt1e6.jpg[0]'
Command :: convert '/tmp/_RH7523920131124-16069-ctt1e6.jpg' '-resize' 'x150' '-crop' '150x150+37+0' '+repage' '/tmp/_RH7523920131124-16
069-ctt1e620131124-16069-1ggirgg'
Completed 500 Internal Server Error in 119696ms

SystemExit (exit):
  app/controllers/items_controller.rb:95:in `block in createzip'
  app/controllers/items_controller.rb:76:in `createzip'


sites/thisite/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/fastcgi.rb:87:in `flush': unknown erro
r (syscall error) (FCGI::Stream::Error)
        from sites/thisite/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/fastcgi.rb:87:in `send_he
aders'
        from sites/thisite/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/fastcgi.rb:68:in `serve'
        from sites/thisite/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/fastcgi.rb:28:in `block i
n run'
        from sites/thisite/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/fastcgi.rb:27:in `each'
        from sites/thisite/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/fastcgi.rb:27:in `run'
        from dispatch.fcgi:32:in `<main>'

代码块看起来像这样

Zip::ZipInputStream::open(params[:file].tempfile) do |zip|
  while(entry = zip.get_next_entry)
    next if entry.name_is_directory?

    fnz = File.join( "#{Rails.root}/tmp", File.basename(entry.name) )
    fd = File.open(fnz, 'wb+')
    fd.write zip.read

    item = Item.new(
      :title => params[:title],
      :summary => params[:summary],
      :stags => params[:stags],
      :active => true,
      :season => params[:season],
      :game => params[:game],
      :match => params[:match]
    )

    puts "%%%%%%%%%%%About to process #{fnz}"
    item.file = fd

    if item.valid?
      if item.save
        @saved += 1
        @user.items << item
        @folder.items << item unless @folder.nil?
      else
        @errors << entry.name
      end
    end
    fd.close
  end
end

dispatch.fcgi文件就是这个:

#!/home/user/ruby/bin/ruby

ENV['RAILS_ENV'] = 'production'
ENV['HOME'] ||= `echo ~`.strip
ENV['GEM_HOME'] = File.expand_path('~/.gems')
ENV['GEM_PATH'] = File.expand_path('~/.gems')

require 'fcgi'
require File.join(File.dirname(__FILE__), '../config/environment.rb')

flog = File.open('fastcgi.log', 'a+')
STDOUT.reopen flog
STDERR.reopen flog
STDOUT.sync = true
STDERR.sync = true

class Rack::PathInfoRewriter
 def initialize(app)
  @app = app
 end

 def call(env)
  env.delete('SCRIPT_NAME')
  parts = env['REQUEST_URI'].split('?')
  env['PATH_INFO'] = parts[0]
  env['QUERY_STRING'] = parts[1].to_s
  @app.call(env)
 end

end

Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(Sampleapp::Application)

提前致谢。

0 个答案:

没有答案