forked from bofh/fetsite
some changes
This commit is contained in:
@@ -31,7 +31,7 @@ Fetsite::Application.configure do
|
||||
# config.force_ssl = true
|
||||
|
||||
# See everything in the log (default is :info)
|
||||
config.log_level = :debug
|
||||
config.log_level = :info
|
||||
|
||||
# Prepend all log lines with the following tags
|
||||
config.log_tags = [ :remote_ip , :uuid ]
|
||||
|
||||
74
config/initializers/sunspot.rb
Normal file
74
config/initializers/sunspot.rb
Normal file
@@ -0,0 +1,74 @@
|
||||
# config/initializers/sunspot.rb
|
||||
module Sunspot
|
||||
#
|
||||
# DataExtractors present an internal API for the indexer to use to extract
|
||||
# field values from models for indexing. They must implement the #value_for
|
||||
# method, which takes an object and returns the value extracted from it.
|
||||
#
|
||||
module DataExtractor #:nodoc: all
|
||||
#
|
||||
# AttributeExtractors extract data by simply calling a method on the block.
|
||||
#
|
||||
class AttributeExtractor
|
||||
def initialize(attribute_name)
|
||||
@attribute_name = attribute_name
|
||||
end
|
||||
|
||||
def value_for(object)
|
||||
Filter.new( object.send(@attribute_name) ).value
|
||||
end
|
||||
end
|
||||
#
|
||||
# BlockExtractors extract data by evaluating a block in the context of the
|
||||
# object instance, or if the block takes an argument, by passing the object
|
||||
# as the argument to the block. Either way, the return value of the block is
|
||||
# the value returned by the extractor.
|
||||
#
|
||||
class BlockExtractor
|
||||
def initialize(&block)
|
||||
@block = block
|
||||
end
|
||||
|
||||
def value_for(object)
|
||||
Filter.new( Util.instance_eval_or_call(object, &@block) ).value
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Constant data extractors simply return the same value for every object.
|
||||
#
|
||||
class Constant
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
|
||||
def value_for(object)
|
||||
Filter.new(@value).value
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# A Filter to allow easy value cleaning
|
||||
#
|
||||
class Filter
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def value
|
||||
strip_control_characters @value
|
||||
end
|
||||
def strip_control_characters(value)
|
||||
return value unless value.is_a? String
|
||||
|
||||
value.chars.inject("") do |str, char|
|
||||
unless char.ascii_only? and (char.ord < 32 or char.ord == 127)
|
||||
str << char
|
||||
end
|
||||
str
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
45
config/unicorn.rb
Normal file
45
config/unicorn.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
# config/unicorn.rb
|
||||
|
||||
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 5)
|
||||
timeout 60
|
||||
preload_app true
|
||||
listen "/var/run/fetsite.sock"
|
||||
stderr_path "/var/log/unicorn.log"
|
||||
stdout_path "/var/log/unicorn.log"
|
||||
|
||||
before_fork do |server, worker|
|
||||
Signal.trap 'TERM' do
|
||||
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
|
||||
Process.kill 'QUIT', Process.pid
|
||||
end
|
||||
|
||||
defined?(ActiveRecord::Base) and
|
||||
ActiveRecord::Base.connection.disconnect!
|
||||
end
|
||||
|
||||
after_fork do |server, worker|
|
||||
Signal.trap 'TERM' do
|
||||
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
|
||||
end
|
||||
|
||||
defined?(ActiveRecord::Base) and
|
||||
ActiveRecord::Base.establish_connection
|
||||
begin
|
||||
uid, gid = Process.euid, Process.egid
|
||||
user, group = 'fetsite', 'nogroup'
|
||||
target_uid = Etc.getpwnam(user).uid
|
||||
target_gid = Etc.getgrnam(group).gid
|
||||
worker.tmp.chown(target_uid, target_gid)
|
||||
if uid != target_uid || gid != target_gid
|
||||
Process.initgroups(user, target_gid)
|
||||
Process::GID.change_privilege(target_gid)
|
||||
Process::UID.change_privilege(target_uid)
|
||||
end
|
||||
rescue => e
|
||||
if RAILS_ENV == 'development'
|
||||
STDERR.puts "couldn't change user, oh well"
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user