ensl.org/config/puma.rb
Ari Timonen 6bcfffa1ee Major update, bugfixes
- Use ruby 2.7.7 as it fixed startup issues
- Update gems
- Remove depr. from puma startup
- Make entry.sh dir-agnostic

Fix tests:
- Use apparition
- Update migrations to use new syntax
- Some other minor changes
2023-02-19 17:08:46 +02:00

56 lines
1.8 KiB
Ruby

# Load dev vars. These are loaded in application but puma needs them too.
require "dotenv"
require 'os'
Dotenv.load('.env.' + ENV['RAILS_ENV'] + '.local', '.env.local', '.env.' + ENV['RAILS_ENV'], '.env')
tag 'ENSL'
# Preload to save memory,
preload_app!
# Start in foreground mode
# daemonize false
# Set vars as we cannmot load them
rails_env = ENV['RAILS_ENV'] || 'development'
app_dir = ENV['APP_PATH'] || '/var/www'
# Set basic puma settings
environment rails_env
#if OS.posix?
# bind "unix://#{app_dir}/tmp/sockets/puma.#{rails_env}.sock"
#end
port Integer(ENV['PUMA_PORT'] || 4000)
# 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
pidfile "#{app_dir}/tmp/pids/puma.pid"
state_path "#{app_dir}/tmp/puma.state"
# 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)
worker_timeout Integer(ENV['PUMA_TIMEOUT'] || 30)
threads Integer(ENV['PUMA_MIN_THREADS'] || 1), Integer(ENV['PUMA_MAX_THREADS'] || 16)
# Allow restart via file
plugin :tmp_restart
on_worker_boot do
require "active_record"
ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end
end
# EXPLAIN This has been added here but why?
on_restart do
ENV["BUNDLE_GEMFILE"] = "#{app_dir}/Gemfile"
Dotenv.overload('.env.' + ENV['RAILS_ENV'] + '.local', '.env.local', '.env.' + ENV['RAILS_ENV'], '.env')
ActiveRecord::Base.connection.disconnect!
end