I've been using Rails 4(installed in user space) with Ruby 2.0 and FastCGI to run a Rails application that uploads a ZIP file which contains several images. Uses the Gem Paperclip to manage the uploads and generates thumbnails and insert a watermark.
The zip file uploads just fine and it process the file unziping the images and creating new Item model to insert into database, but it hangs at certain point and drops the error:
%%%%%%%%%%%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>'
And the block of code looks like this
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
And the dispatch.fcgi file is this one:
#!/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)
Thanks in advance.