Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (39 sloc) 1.514 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
require File.expand_path('../load_config', __FILE__)

# Enable and set these to run the worker as a different user/group
#user = 'diaspora'
#group = 'diaspora'

worker_processes AppConfig.server.unicorn_worker.to_i

## Load the app before spawning workers
preload_app true

# How long to wait before killing an unresponsive worker
timeout AppConfig.server.unicorn_timeout.to_i

@sidekiq_pid = nil

#pid '/var/run/diaspora/diaspora.pid'
#listen '/var/run/diaspora/diaspora.sock', :backlog => 2048


stderr_path AppConfig.server.stderr_log.get if AppConfig.server.stderr_log.present?
stdout_path AppConfig.server.stdout_log.get if AppConfig.server.stdout_log.present?

before_fork do |server, worker|
  # If using preload_app, enable this line
  ActiveRecord::Base.connection.disconnect!

  # disconnect redis if in use
  unless AppConfig.single_process_mode?
    Sidekiq.redis {|redis| redis.client.disconnect }
  end
  
  if AppConfig.server.embed_sidekiq_worker?
    @sidekiq_pid ||= spawn('bundle exec sidekiq')
  end

  old_pid = '/var/run/diaspora/diaspora.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|
  # If using preload_app, enable this line
  ActiveRecord::Base.establish_connection

  # We don't generate uuids in the frontend, but let's be on the safe side
  UUID.generator.next_sequence
end
Something went wrong with that request. Please try again.