2020-04-05 03:30:14 +00:00
|
|
|
# Load dev vars. These are loaded in application but puma needs them too.
|
2014-04-15 09:59:52 +00:00
|
|
|
require "dotenv"
|
2020-04-05 03:30:14 +00:00
|
|
|
Dotenv.load('.env.' + ENV['RAILS_ENV'] + '.local', '.env.local', '.env.' + ENV['RAILS_ENV'], '.env')
|
2014-04-15 09:59:52 +00:00
|
|
|
|
|
|
|
tag 'ENSL'
|
|
|
|
|
2020-03-26 01:52:20 +00:00
|
|
|
# Preload to save memory,
|
2014-04-15 09:59:52 +00:00
|
|
|
preload_app!
|
2020-03-26 01:52:20 +00:00
|
|
|
|
|
|
|
# Start in foreground mode
|
2018-04-15 11:17:59 +00:00
|
|
|
daemonize false
|
2014-04-15 09:59:52 +00:00
|
|
|
|
2020-03-26 01:52:20 +00:00
|
|
|
# Rack up?
|
2020-03-26 00:34:05 +00:00
|
|
|
rackup DefaultRackup
|
|
|
|
|
2020-03-26 01:52:20 +00:00
|
|
|
# Set vars as we cannmot load them
|
2020-03-26 00:34:05 +00:00
|
|
|
rails_env = ENV['RAILS_ENV'] || 'development'
|
|
|
|
app_dir = ENV['DEPLOY_PATH'] || '/var/www'
|
|
|
|
|
2020-03-26 01:52:20 +00:00
|
|
|
# Set basic puma settings
|
2020-03-26 00:34:05 +00:00
|
|
|
environment rails_env
|
|
|
|
bind "unix://#{app_dir}/tmp/sockets/puma.sock"
|
|
|
|
port Integer(ENV['PUMA_PORT'] || 4000)
|
|
|
|
|
2020-03-26 01:52:20 +00:00
|
|
|
# Redirect stdout only in production. Dev mode needs it for debug
|
|
|
|
if rails_env.downcase != 'development'
|
|
|
|
stdout_redirect "#{app_dir}/log/puma.stdout.log", \
|
|
|
|
"#{app_dir}/log/puma.stderr.log", true
|
|
|
|
end
|
2020-03-26 00:34:05 +00:00
|
|
|
|
2020-03-26 01:52:20 +00:00
|
|
|
pidfile "#{app_dir}/tmp/pids/puma.pid"
|
|
|
|
state_path "#{app_dir}/tmp/puma.state"
|
2020-03-14 19:43:19 +00:00
|
|
|
|
2020-03-26 00:34:05 +00:00
|
|
|
# FIXME: sometimes the app becomes super slow if workers are used, investigate
|
|
|
|
workers Integer(ENV['PUMA_WORKERS']) if (ENV.has_key?("PUMA_WORKERS") && ENV['PUMA_WORKERS'].to_i > 0)
|
2014-04-15 09:59:52 +00:00
|
|
|
worker_timeout Integer(ENV['PUMA_TIMEOUT'] || 30)
|
|
|
|
threads Integer(ENV['PUMA_MIN_THREADS'] || 1), Integer(ENV['PUMA_MAX_THREADS'] || 16)
|
|
|
|
|
2020-03-26 01:52:20 +00:00
|
|
|
# Allow restart via file
|
2020-03-26 00:34:05 +00:00
|
|
|
plugin :tmp_restart
|
|
|
|
|
2014-04-15 09:59:52 +00:00
|
|
|
on_worker_boot do
|
2020-03-26 00:34:05 +00:00
|
|
|
require "active_record"
|
2014-04-15 09:59:52 +00:00
|
|
|
ActiveSupport.on_load(:active_record) do
|
2020-03-26 00:34:05 +00:00
|
|
|
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
|
|
|
|
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
|
2014-04-15 09:59:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-25 01:47:54 +00:00
|
|
|
# EXPLAIN This has been added here but why?
|
2014-04-15 09:59:52 +00:00
|
|
|
on_restart do
|
2020-03-26 00:34:05 +00:00
|
|
|
ENV["BUNDLE_GEMFILE"] = "#{app_dir}/Gemfile"
|
2014-04-15 09:59:52 +00:00
|
|
|
Dotenv.overload
|
|
|
|
ActiveRecord::Base.connection.disconnect!
|
|
|
|
end
|