PUMA配置,启动与停止

image.png

获取当前应用的跟路径

application_path=File.expand_path('../..', FILE)

获取 RAILS_ENV环境变量

env = ENV.fetch("RAILS_ENV") { "development" }
environment env
port = ENV.fetch("PORT") { 3000 }

directory "#{application_path}/"

pidfile路径,必须设置这个才能使用pumactl

pidfile "#{application_path}/tmp/puma.pid"
state_path "#{application_path}/tmp/sockets/puma.state"

puma的日志输出和错误输出路径

stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"

port port
workers 1 # worker一般设置和CPU核数一致即可
threads 5,10 # 每个worker的线程数
daemonize true
preload_app! # workers=1时没什么用

before_fork do
ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
end

on_worker_boot do
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end

plugin :tmp_restart

你可能感兴趣的:(PUMA配置,启动与停止)