-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuma.rb
More file actions
68 lines (53 loc) · 1.68 KB
/
puma.rb
File metadata and controls
68 lines (53 loc) · 1.68 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# puma logging
DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S %z'.freeze
FORMATTED_OUTPUT = ->(input) { "#{Time.now.strftime DATETIME_FORMAT} : |Puma| #{input}"}
def STDOUT.puts(arg)
super(FORMATTED_OUTPUT.call(arg))
end
def STDERR.puts(arg)
super(FORMATTED_OUTPUT.call(arg))
end
log_formatter do |str|
FORMATTED_OUTPUT.call(str)
end
# log requests
log_requests true
stdout_redirect './log/app.log', './log/err.log', true
# preload first to load .env file
preload_app!
# update spa files
require_relative 'spa/updater'
SpaFilesUpdater.update!
# puma files
pidfile "./tmp/puma/puma.pid"
state_path "./tmp/puma/puma.state"
bind "unix://./tmp/puma/puma.sock"
# puma workers and threads
processes_count = Integer(ENV['PUMA_MAX_PROCESSES'] || 5)
workers processes_count
threads_count = Integer(ENV['PUMA_MAX_THREADS'] || 5)
threads threads_count, threads_count
# puma port and env
port ENV['PORT'] || 5555
environment ENV['WP_ENV'] || 'development'
before_fork do
# release db connections
Sequel::Model.db.disconnect
# enable pumma killer
if ENV['PUMA_WORKER_KILLER'] == 'true'
require 'puma_worker_killer'
# settings
killer_ram = processes_count * 200 # mb
killer_frequency = Integer((ENV['PUMA_WORKER_KILLER_INTERVAL_IN_MINUTES'] || 10)) * 60 # seconds
puts "Puma worker killer enabled: Max RAM for cluster => #{killer_ram} MB, frequency => #{killer_frequency} seconds"
PumaWorkerKiller.config do |config|
config.ram = killer_ram
config.frequency = killer_frequency
config.rolling_restart_frequency = false
end
PumaWorkerKiller.start
end
end
on_worker_boot do
defined?(Sequel::Model) and Sequel::Model.db.connect(DB.uri)
end