announcement-test/temp_file/config/unicorn.rb

59 lines
2.1 KiB
Ruby
Raw Normal View History

2021-11-27 05:37:57 +00:00
# unicorn_rails -c config/unicorn.rb -E development -D
# kill -s USR2 PID_OF_MASTER
rails_root = `pwd`.gsub("\n", "")
rails_env = ENV['RAILS_ENV'] || 'production'
2022-05-29 04:59:54 +00:00
cpu_cores = %x(cat /proc/cpuinfo | grep processor | wc -l).sub("\n",'').to_i * 3 / 4 rescue 2
default_cpu_cores = cpu_cores
2023-04-08 15:12:29 +00:00
if File.exist?("#{rails_root}/cpu_cores.txt")
2024-02-24 06:54:42 +00:00
cpu_cores = File.read("#{rails_root}/cpu_cores.txt").force_encoding('utf-8').strip.to_i rescue default_cpu_cores
2022-10-04 05:27:32 +00:00
else
begin
2024-02-24 06:54:42 +00:00
if (File.exist?("#{rails_root}/../cpu_cores.txt") rescue false)
cpu_cores = File.read("#{rails_root}/../cpu_cores.txt").force_encoding('utf-8').strip.to_i
elsif (File.exist?("#{ENV['HOME']}/cpu_cores.txt") rescue false)
cpu_cores = File.read("#{ENV['HOME']}/cpu_cores.txt").force_encoding('utf-8').strip.to_i
end
2022-10-04 05:27:32 +00:00
rescue => e
cpu_cores = default_cpu_cores
end
2022-05-29 04:59:54 +00:00
end
cpu_cores = 1 if (cpu_cores < 1)
2021-11-27 05:37:57 +00:00
worker_processes (rails_env == 'production' ? cpu_cores : 1)
# preload_app true
timeout 30
2024-02-24 06:54:42 +00:00
require File.expand_path("../set_global_variable",__FILE__)
site = Site.first
if (site.use_advanced_cache rescue false)
listen "#{rails_root}/tmp/unicorn_rails.sock", :backlog => 4000
pid "#{rails_root}/tmp/pids/unicorn_rails.pid"
2021-11-27 05:37:57 +00:00
2024-02-24 06:54:42 +00:00
roda_pid_file = "#{rails_root}/tmp/pids/unicorn.pid"
roda_pid = File.open(roda_pid_file, 'r').read().gsub("\n",'').to_i rescue nil
if !roda_pid || !system("kill -0 #{roda_pid}")
`cd #{rails_root}/config/roda && ulimit -n 100000 && bundle exec unicorn -c unicorn.rb -D -E production`
end
else
listen "#{rails_root}/tmp/unicorn.sock", :backlog => 4000
pid "#{rails_root}/tmp/pids/unicorn.pid"
end
if Unicorn::Configurator::RACKUP[:daemonized]
stderr_path "#{rails_root}/log/unicorn.log"
stdout_path "#{rails_root}/log/unicorn.log"
end
ENV['worker_num'] = '0'
2021-11-27 05:37:57 +00:00
before_fork do |server, worker|
ENV['worker_num'] = "#{worker.nr}"
2024-02-24 06:54:42 +00:00
old_pid = "#{server.config[:pid]}.oldbin"
if File.exist?(old_pid)
2021-11-27 05:37:57 +00:00
begin
2024-02-24 06:54:42 +00:00
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
2021-11-27 05:37:57 +00:00
rescue Errno::ENOENT, Errno::ESRCH
end
end
2022-05-29 04:59:54 +00:00
end