From 821e6b276d97348a32619b555b845a6a619354ca Mon Sep 17 00:00:00 2001 From: f Date: Mon, 8 Apr 2019 15:31:29 -0300 Subject: [PATCH] docker --- .dockerignore | 23 +++++++++++++++++++++++ config/puma.rb | 19 ++++++++++--------- entrypoint.sh | 24 ++++++++++++++++++++++++ monit.conf | 7 +++++++ 4 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 entrypoint.sh create mode 100644 monit.conf diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..6377ca43 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,23 @@ +Dockerfile +node_modules/ +tmp/ +log/ +public/ +docs/ +bin/ +db/ +lib/ +test/ +tmp/ +vendor/ +config.ru +LICENSE +Makefile +monit.conf +README.md +TODO* +web@.service +_usuarias/ +_invitadxs/ +_deploy/ +_sites/ diff --git a/config/puma.rb b/config/puma.rb index 7d53b137..4360a380 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -23,7 +23,7 @@ environment ENV.fetch('RAILS_ENV') { 'development' } # 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 @@ -32,15 +32,15 @@ environment ENV.fetch('RAILS_ENV') { 'development' } # you need to make sure to reconnect any threads in the `on_worker_boot` # block. # -# preload_app! +preload_app! # If you are preloading your application and using Active Record, it's # recommended that you close any connections to the database before workers # are forked to prevent connection leakage. # -# before_fork do -# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) -# end +before_fork do + ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord) +end # The code in the `on_worker_boot` will be called if you are using # clustered mode by specifying a number of `workers`. After each worker @@ -49,10 +49,11 @@ environment ENV.fetch('RAILS_ENV') { 'development' } # or connections that may have been created at application boot, as Ruby # cannot share connections between processes. # -# on_worker_boot do -# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) -# end -# +on_worker_boot do + ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +end # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart + +pidfile 'tmp/puma.pid' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..079a513c --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/sh +set -e +export RAILS_ENV=production + +case $1 in + rails) + cd /srv/http + bundle exec rake db:migrate + bundle exec rake db:seed + bundle exec puma -d config.ru + exit $? + ;; + darkhttpd) + darkhttpd /srv/http/public \ + --no-server-id \ + --pidfile /tmp/darkhttpd.pid \ + --uid darkhttpd \ + --gid www-data \ + --no-listing \ + --daemon \ + --port 8080 + exit $? + ;; +esac diff --git a/monit.conf b/monit.conf new file mode 100644 index 00000000..3d686349 --- /dev/null +++ b/monit.conf @@ -0,0 +1,7 @@ +check process rails with pidfile /srv/http/tmp/puma.pid + start program = "/usr/bin/entrypoint rails" as uid app + stop program = "/bin/sh -c 'cat /srv/http/tmp/puma.pid | xargs kill'" + +check process static with pidfile /tmp/darkhttpd.pid + start program = "/usr/bin/entrypoint darkhttpd" + stop program = "/bin/sh -c 'cat /tmp/darkhttpd.pid | xargs kill'"