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")
|
2022-10-04 05:27:32 +00:00
|
|
|
cpu_cores = File.read("#{rails_root}/cpu_cores.txt").force_encoding('utf-8').sub("\n",'').to_i rescue default_cpu_cores
|
|
|
|
else
|
|
|
|
begin
|
2023-04-08 15:12:29 +00:00
|
|
|
cpu_cores = File.read("#{rails_root}/../cpu_cores.txt").force_encoding('utf-8').sub("\n",'').to_i if (File.exist?("#{rails_root}/../cpu_cores.txt") rescue false)
|
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
|
|
|
|
|
2022-05-29 04:59:54 +00:00
|
|
|
listen "#{rails_root}/tmp/unicorn.sock", :backlog => 4000
|
2021-11-27 05:37:57 +00:00
|
|
|
stderr_path "#{rails_root}/log/unicorn.log"
|
|
|
|
stdout_path "#{rails_root}/log/unicorn.log"
|
|
|
|
|
|
|
|
before_fork do |server, worker|
|
|
|
|
ENV['worker_num'] = "#{worker.nr}"
|
|
|
|
old_pid = "#{rails_root}/tmp/pids/unicorn.pid.oldbin"
|
2023-04-08 15:12:29 +00:00
|
|
|
if File.exist?(old_pid) && server.pid != old_pid
|
2021-11-27 05:37:57 +00:00
|
|
|
begin
|
|
|
|
Process.kill("QUIT", File.read(old_pid).to_i)
|
|
|
|
rescue Errno::ENOENT, Errno::ESRCH
|
|
|
|
end
|
|
|
|
end
|
2022-05-29 04:59:54 +00:00
|
|
|
end
|
|
|
|
require File.expand_path("../set_global_variable",__FILE__)
|