<commit_before># This file has been generated from unicorn_template.rb.erb which is greatly inspired from:
# https://github.com/ricodigo/ricodigo-capistrano-recipes/blob/master/generators/unicorn.rb.erb
#
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.

# Local variables
old_pid = '<%= unicorn_pid + ".old" %>'

# Unicorn setup

worker_processes <%= unicorn_workers %>
timeout <%= unicorn_workers_timeout %>

# Listen on a Unix data socket
listen '<%= unicorn_socket %>', :backlog => 1024
pid '<%= unicorn_pid %>'

user '<%= unicorn_user %>', '<%= unicorn_group %>'

# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory '<%= "#{deploy_to}/current" %>'

stderr_path '<%= "#{logs_path}/unicorn.stderr.log" %>'
stdout_path '<%= "#{logs_path}/unicorn.stdout.log" %>'

preload_app true

GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)

before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect
  end
  if File.exists?(old_pid) && server.pid != old_pid
    pid = File.read(old_pid).to_i
    begin
      puts ">> Killing old unicorn process"
      Process.kill("QUIT", pid)
    rescue Errno::ECHILD, Errno::ESRCH => e
      $stderr.puts ">> Process #{pid} has stopped"
    rescue Errno::ENOENT => e
      $stderr.puts ">> Error killing previous instance. #{e.message}"
      # someone else did our job for us
    end
  end
end

after_fork do |server, worker|
  begin
    uid, gid = Process.euid, Process.egid

    target_uid = File.stat(Rails.root).uid
    user = Etc.getpwuid(target_uid).name

    target_gid = File.stat(Rails.root).gid
    group = Etc.getgrgid(target_gid).name

    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
    STDERR.puts "cannot change privileges on #{Rails.env} environment"
    STDERR.puts "  #{e}"
  end
end<commit_msg>more unicorn config fixes<commit_after># This file has been generated from unicorn_template.rb.erb which is greatly inspired from:
# https://github.com/ricodigo/ricodigo-capistrano-recipes/blob/master/generators/unicorn.rb.erb
#
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
# documentation.

# Local variables
old_pid = '<%= unicorn_pid + ".old" %>'

# Unicorn setup

worker_processes <%= unicorn_workers %>
timeout <%= unicorn_workers_timeout %>

# Listen on a Unix data socket
listen '<%= unicorn_socket %>', :backlog => 1024
pid '<%= unicorn_pid %>'

user '<%= unicorn_user %>', '<%= unicorn_group %>'

# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory '<%= "#{deploy_to}/current" %>'

stderr_path '<%= "#{logs_path}/unicorn.stderr.log" %>'
stdout_path '<%= "#{logs_path}/unicorn.stdout.log" %>'

preload_app true

before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.connection.disconnect!
  end

  # Before forking, kill the master process that belongs to the .oldbin PID.
  # This enables 0 downtime deploys.
  old_pid = "/tmp/unicorn.my_site.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|
  # the following is *required* for Rails + "preload_app true",
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection
  end

  # if preload_app is true, then you may also want to check and
  # restart any other shared sockets/descriptors such as Memcached,
  # and Redis.  TokyoCabinet file handles are safe to reuse
  # between any number of forked children (assuming your kernel
  # correctly implements pread()/pwrite() system calls)
end
{'fraction_non_alphanumeric': 0.12090447623442548, 'fraction_numerical': 0.002076603599446239, 'mean_word_length': 4.2355072463768115, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 34, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4127746', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1403, 'n_words': 386}