#!/usr/bin/env ruby require 'unicorn-cuba-base' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) Application.new('httpthumbnailer', port: 3100) do cli do description 'Image thumbnailing HTTP server' switch :formats, short: :F, description: 'print backend versions and supported formats' option :limit_disk, cast: Integer, description: 'image cache temporary file size limit in MiB', default: 1024 switch :no_optimization, description: 'disable load time size hinting and prescaling optimizations' version (Pathname.new(__FILE__).dirname + '..' + 'VERSION').read end settings do |settings| if settings.formats require 'httpthumbnailer/plugin/thumbnailer' puts "Versions:" puts "\t#{Plugin::Thumbnailer::Service.rmagick_version}" puts "\t#{Plugin::Thumbnailer::Service.magick_version}" puts puts "Input formats:" puts "\t#{Plugin::Thumbnailer::Service.input_formats.join(' ')}" puts puts "Output formats:" puts "\t#{Plugin::Thumbnailer::Service.output_formats.join(' ')}" exit 0 end Controler.settings[:optimization] = (not settings.no_optimization) Controler.settings[:limit_memory] = settings.limit_memory * 1024**2 Controler.settings[:limit_map] = settings.limit_disk * 1024**2 Controler.settings[:limit_disk] = settings.limit_disk * 1024**2 end main do |settings| require 'httpthumbnailer/error_reporter' require 'httpthumbnailer/thumbnailer' class HTTPThumbniler < Controler extend Stats def_stats( :workers, :total_requests, :total_errors ) raindrops_stats = Raindrops::Middleware::Stats.new self.use Raindrops::Middleware, stats: raindrops_stats StatsReporter << HTTPThumbniler.stats StatsReporter << raindrops_stats StatsReporter << Plugin::Thumbnailer::Service.stats StatsReporter << Plugin::ResponseHelpers.stats self.define do HTTPThumbniler.stats.incr_total_requests on error? do HTTPThumbniler.stats.incr_total_errors run ErrorReporter end on 'stats' do run StatsReporter end on 'health_check' do write_plain 200, 'OK' end on root do write_plain 200, 'HTTP Thumbnailer' end on true do run Thumbnailer end end end HTTPThumbniler end after_fork do |server, worker| HTTPThumbniler.stats.incr_workers end end