diff --git a/.env.development b/.env.development index b5613d1..78f9c4a 100644 --- a/.env.development +++ b/.env.development @@ -7,7 +7,7 @@ APP_SECRET=fe837ea72667ec3d8ecb94cfba1a1bba DEPLOY_PATH=/var/www -PUMA_WORKERS=5 +PUMA_WORKERS=0 PUMA_MIN_THREADS=1 PUMA_MAX_THREADS=16 PUMA_PORT=4000 diff --git a/config/puma.rb b/config/puma.rb index 0145509..97b7989 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,32 +6,40 @@ tag 'ENSL' preload_app! daemonize false -# FIXME -#stderr_path = "#{base_path}/log/puma.stderr.log" -#stdout_path = "#{base_path}/log/puma.stdout.log" -#directory base_path +rackup DefaultRackup + +rails_env = ENV['RAILS_ENV'] || 'development' +app_dir = ENV['DEPLOY_PATH'] || '/var/www' + +environment rails_env +bind "unix://#{app_dir}/tmp/sockets/puma.sock" +port Integer(ENV['PUMA_PORT'] || 4000) + +stdout_redirect "#{app_dir}/log/puma.stdout.log", \ + "#{app_dir}/log/puma.stderr.log", true + #pidfile "#{base_path}/tmp/pids/puma.pid" #state_path "#{base_path}/tmp/pids/puma.state" #stdout_redirect stdout_path, stderr_path -rackup DefaultRackup - -environment ENV['RACK_ENV'] || 'production' -#bind "unix://#{base_path}/tmp/sockets/puma.sock" -port Integer(ENV['PUMA_PORT'] || 4000) +# 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) -workers Integer(ENV['PUMA_WORKERS'] || 4) threads Integer(ENV['PUMA_MIN_THREADS'] || 1), Integer(ENV['PUMA_MAX_THREADS'] || 16) +plugin :tmp_restart + on_worker_boot do + require "active_record" ActiveSupport.on_load(:active_record) do - ActiveRecord::Base.establish_connection + 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"] = "#{current_path}/Gemfile" + ENV["BUNDLE_GEMFILE"] = "#{app_dir}/Gemfile" Dotenv.overload ActiveRecord::Base.connection.disconnect! end