aboutsummaryrefslogtreecommitdiff
path: root/config
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2020-10-06 11:52:22 +0200
committerhellekin <hellekin@cepheide.org>2020-10-06 11:52:22 +0200
commitb316543014e2c9b9444edd3d713cd02b647cfea3 (patch)
treef7cca0761765c7955782549186c87db89e272313 /config
parentc2a1ba4f7a490916ffc3daf1dc677d695a7a9a61 (diff)
downloadincommon-map-b316543014e2c9b9444edd3d713cd02b647cfea3.tar.gz
Add code for deployment
Diffstat (limited to 'config')
-rw-r--r--config/database.yml2
-rw-r--r--config/puma.rb31
2 files changed, 28 insertions, 5 deletions
diff --git a/config/database.yml b/config/database.yml
index 233210c..74519f2 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -86,5 +86,5 @@ test:
production:
<<: *default
database: incommon_map_production
- username: incommon_map
+ username: incommon
password: <%= ENV['INCOMMON_MAP_DATABASE_PASSWORD'] %>
diff --git a/config/puma.rb b/config/puma.rb
index 5ed4437..8b894d0 100644
--- a/config/puma.rb
+++ b/config/puma.rb
@@ -8,16 +8,33 @@ max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
+app_dir = File.expand_path('../..', __FILE__)
+shared_dir = "#{app_dir}/tmp"
+
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
-port ENV.fetch("PORT") { 3000 }
+if Rails.env.development?
+ port ENV.fetch("PORT") { 3000 }
+else
+ bind "unix://#{shared_dir}/sockets/puma.sock";
+end
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
-pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
+pidfile ENV.fetch("PIDFILE") { "#{shared_dir}/pids/server.pid" }
+# Keep puma state
+state_path "#{shared_dir}/pids/puma.state"
+
+# Logging
+if Rails.env.development?
+ # Do not redirect STDOUT so we can use byebug!
+ stdout_redirect nil, "#{app_dir}/log/puma.stderr.log", true
+else
+ stdout_redirect "#{app_dir}/log/puma.stdout.log", "#{app_dir}/log/puma.stderr.log", true
+end
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
@@ -25,14 +42,20 @@ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
-# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
+workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
-# preload_app!
+preload_app!
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
+
+on_worker_boot do
+ require "active_record"
+ ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
+ ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
+end