Add unicorn as backup

This commit is contained in:
Ari Timonen 2020-03-26 01:32:35 +02:00
parent 420930f2b9
commit 1bed2c08a9
3 changed files with 147 additions and 45 deletions

21
Gemfile
View file

@ -13,12 +13,13 @@ gem 'dotenv-rails'
# DB # DB
# Fixme: using this bc puma startup problem # Fixme: using this bc puma startup problem
gem 'active_record_union' gem 'active_record_union'
gem 'dalli', '~> 2.7.0' gem 'dalli'
gem 'mysql2' gem 'mysql2'
# Web server # Web server
gem 'faraday', '~> 0.9.0' gem 'faraday'
gem 'puma' gem 'puma'
gem 'unicorn'
# Model plugins # Model plugins
gem 'unread' gem 'unread'
@ -55,9 +56,6 @@ gem 'jquery-rails'
gem 'tinymce-rails' gem 'tinymce-rails'
gem 'i18n-js' gem 'i18n-js'
# Please install nodejs locally.
# gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux'
gem 'bourbon','~> 3.1.8' gem 'bourbon','~> 3.1.8'
# Fix icons before updating # Fix icons before updating
@ -82,8 +80,7 @@ group :development do
gem 'annotate' gem 'annotate'
gem 'better_errors' gem 'better_errors'
gem 'binding_of_caller' gem 'binding_of_caller'
gem 'spring', '2.0.2' gem 'web-console'
gem 'web-console', '3.7.0'
gem 'rubocop' gem 'rubocop'
end end
@ -98,6 +95,7 @@ group :test do
# FIXME: Downgraded b/c of deprecations, fix static attributes # FIXME: Downgraded b/c of deprecations, fix static attributes
gem 'factory_bot_rails', '4.10.0' gem 'factory_bot_rails', '4.10.0'
# Feature testing
gem 'capybara' gem 'capybara'
gem 'phantomjs', require: 'phantomjs/poltergeist' gem 'phantomjs', require: 'phantomjs/poltergeist'
gem 'poltergeist' gem 'poltergeist'
@ -105,10 +103,11 @@ group :test do
# Fix FF issue # Fix FF issue
gem 'geckodriver-helper' gem 'geckodriver-helper'
# Fix legacy issue # Fix legacy issue
gem 'rails-controller-testing' gem 'rails-controller-testing'
# Goverage # Coverage
gem 'simplecov', require: false gem 'simplecov', require: false
gem 'timecop' gem 'timecop'
@ -130,9 +129,7 @@ end
group :development, :test do group :development, :test do
gem 'pry-rails' gem 'pry-rails'
gem 'pry-byebug' gem 'pry-byebug'
gem 'spring'
# gem 'spring'
# For n+1 uqeries # For n+1 uqeries
gem 'bullet' # gem 'bullet'
end end

View file

@ -31,9 +31,9 @@ GIT
GIT GIT
remote: https://github.com/rspec/rspec-rails remote: https://github.com/rspec/rspec-rails
revision: e886b55c7f6d311b4bc5a7785a288c0ea5032fb6 revision: 0cafe7ff69d3b11a35e007c76e16e27069f67d6d
specs: specs:
rspec-rails (4.0.0.pre) rspec-rails (4.1.0.pre)
actionpack (>= 4.2) actionpack (>= 4.2)
activesupport (>= 4.2) activesupport (>= 4.2)
railties (>= 4.2) railties (>= 4.2)
@ -113,7 +113,7 @@ GEM
zeitwerk (~> 2.2) zeitwerk (~> 2.2)
addressable (2.7.0) addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0) public_suffix (>= 2.0.2, < 5.0)
annotate (3.1.0) annotate (3.1.1)
activerecord (>= 3.2, < 7.0) activerecord (>= 3.2, < 7.0)
rake (>= 10.4, < 14.0) rake (>= 10.4, < 14.0)
archive-zip (0.12.0) archive-zip (0.12.0)
@ -132,9 +132,6 @@ GEM
sass (>= 3.2.0) sass (>= 3.2.0)
thor thor
builder (3.2.4) builder (3.2.4)
bullet (6.1.0)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
byebug (11.1.1) byebug (11.1.1)
capybara (3.31.0) capybara (3.31.0)
addressable addressable
@ -197,7 +194,7 @@ GEM
factory_bot_rails (4.10.0) factory_bot_rails (4.10.0)
factory_bot (~> 4.10.0) factory_bot (~> 4.10.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faraday (0.9.2) faraday (0.17.3)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
ffi (1.12.2) ffi (1.12.2)
font-awesome-sass (4.1.0) font-awesome-sass (4.1.0)
@ -215,13 +212,12 @@ GEM
mime-types (>= 1.6) mime-types (>= 1.6)
representable (~> 3.0) representable (~> 3.0)
retriable (>= 2.0, < 4.0) retriable (>= 2.0, < 4.0)
googleauth (0.5.1) googleauth (0.9.0)
faraday (~> 0.9) faraday (~> 0.12)
jwt (~> 1.4) jwt (>= 1.4, < 3.0)
logging (~> 2.0) memoist (~> 0.16)
memoist (~> 0.12)
multi_json (~> 1.11) multi_json (~> 1.11)
os (~> 0.9) os (>= 0.9, < 2.0)
signet (~> 0.7) signet (~> 0.7)
haml (5.1.2) haml (5.1.2)
temple (>= 0.8.0) temple (>= 0.8.0)
@ -250,11 +246,8 @@ GEM
railties (>= 4.2.0) railties (>= 4.2.0)
thor (>= 0.14, < 2.0) thor (>= 0.14, < 2.0)
json (2.3.0) json (2.3.0)
jwt (1.5.6) jwt (2.2.1)
little-plugger (1.1.4) kgio (2.11.3)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
loofah (2.4.0) loofah (2.4.0)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
@ -285,7 +278,7 @@ GEM
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
nokogumbo (2.0.2) nokogumbo (2.0.2)
nokogiri (~> 1.8, >= 1.8.4) nokogiri (~> 1.8, >= 1.8.4)
os (0.9.6) os (1.0.1)
parallel (1.19.1) parallel (1.19.1)
parser (2.7.0.5) parser (2.7.0.5)
ast (~> 2.4.0) ast (~> 2.4.0)
@ -342,6 +335,7 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0) thor (>= 0.20.3, < 2.0)
rainbow (3.0.0) rainbow (3.0.0)
raindrops (0.19.1)
rake (10.5.0) rake (10.5.0)
rb-fsevent (0.10.3) rb-fsevent (0.10.3)
rb-inotify (0.10.1) rb-inotify (0.10.1)
@ -402,8 +396,7 @@ GEM
sixarm_ruby_unaccent (1.2.0) sixarm_ruby_unaccent (1.2.0)
sort_alphabetical (1.1.0) sort_alphabetical (1.1.0)
unicode_utils (>= 1.2.2) unicode_utils (>= 1.2.2)
spring (2.0.2) spring (2.1.0)
activesupport (>= 4.2)
sprockets (3.7.2) sprockets (3.7.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
@ -420,7 +413,7 @@ GEM
time_difference (0.5.0) time_difference (0.5.0)
activesupport activesupport
timecop (0.9.1) timecop (0.9.1)
tinymce-rails (5.2.0) tinymce-rails (5.2.1)
railties (>= 3.1.1) railties (>= 3.1.1)
tzinfo (1.2.6) tzinfo (1.2.6)
thread_safe (~> 0.1) thread_safe (~> 0.1)
@ -430,14 +423,16 @@ GEM
json (>= 1.8.0) json (>= 1.8.0)
unicode-display_width (1.6.1) unicode-display_width (1.6.1)
unicode_utils (1.4.0) unicode_utils (1.4.0)
uniform_notifier (1.13.0) unicorn (5.5.4)
kgio (~> 2.6)
raindrops (~> 0.7)
unread (0.11.0) unread (0.11.0)
activerecord (>= 3) activerecord (>= 3)
web-console (3.7.0) web-console (4.0.1)
actionview (>= 5.0) actionview (>= 6.0.0)
activemodel (>= 5.0) activemodel (>= 6.0.0)
bindex (>= 0.4.0) bindex (>= 0.4.0)
railties (>= 5.0) railties (>= 6.0.0)
websocket-driver (0.7.1) websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4) websocket-extensions (0.1.4)
@ -458,19 +453,18 @@ DEPENDENCIES
binding_of_caller binding_of_caller
bluecloth bluecloth
bourbon (~> 3.1.8) bourbon (~> 3.1.8)
bullet
capybara capybara
carrierwave carrierwave
codeclimate-test-reporter codeclimate-test-reporter
coffee-rails coffee-rails
country_select country_select
dalli (~> 2.7.0) dalli
database_cleaner-active_record database_cleaner-active_record
database_cleaner-redis database_cleaner-redis
dotenv-rails dotenv-rails
dynamic_form dynamic_form
factory_bot_rails (= 4.10.0) factory_bot_rails (= 4.10.0)
faraday (~> 0.9.0) faraday
font-awesome-sass (~> 4.1.0.0) font-awesome-sass (~> 4.1.0.0)
geckodriver-helper geckodriver-helper
google-api-client (~> 0.10.3) google-api-client (~> 0.10.3)
@ -507,15 +501,16 @@ DEPENDENCIES
selenium-webdriver selenium-webdriver
signet (= 0.11.0) signet (= 0.11.0)
simplecov simplecov
spring (= 2.0.2) spring
steam-condenser! steam-condenser!
test-unit test-unit
time_difference time_difference
timecop timecop
tinymce-rails tinymce-rails
uglifier (~> 2.5.0) uglifier (~> 2.5.0)
unicorn
unread unread
web-console (= 3.7.0) web-console
will_paginate will_paginate
RUBY VERSION RUBY VERSION

110
config/unicorn.rb Normal file
View file

@ -0,0 +1,110 @@
# Sample verbose configuration file for Unicorn (not Rack)
#
# This configuration file documents many features of Unicorn
# that may not be needed for some applications. See
# https://yhbt.net/unicorn/examples/unicorn.conf.minimal.rb
# for a much simpler configuration file.
#
# See https://yhbt.net/unicorn/Unicorn/Configurator.html for complete
# documentation.
# Use at least one worker per core if you're on a dedicated server,
# more will usually help for _short_ waits on databases/caches.
worker_processes 4
# Since Unicorn is never exposed to outside clients, it does not need to
# run on the standard HTTP port (80), there is no reason to start Unicorn
# as root unless it's from system init scripts.
# If running the master process as root and the workers as an unprivileged
# user, do this to switch euid/egid in the workers (also chowns logs):
# user "unprivileged_user", "unprivileged_group"
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
working_directory "/var/www" # available in 0.94.0+
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen File.join("tmp/sockets/unicorn.sock"), :backlog => 64
listen 4000, :tcp_nopush => true
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
# feel free to point this anywhere accessible on the filesystem
pid File.join("tmp/pids/unicorn.pid")
# By default, the Unicorn logger will write to stderr.
# Additionally, ome applications/frameworks log to stderr or stdout,
# so prevent them from going to /dev/null when daemonized here:
stderr_path File.join("log/unicorn.stderr.log")
stdout_path File.join("log/unicorn.stdout.log")
# combine Ruby 2.0.0+ with "preload_app true" for memory savings
preload_app true
# Enable this flag to have unicorn test client connections by writing the
# beginning of the HTTP headers before calling the application. This
# prevents calling the application for connections that have disconnected
# while queued. This is only guaranteed to detect clients on the same
# host unicorn runs on, and unlikely to detect disconnects even on a
# fast LAN.
check_client_connection false
# local variable to guard against running a hook multiple times
run_once = true
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
# Occasionally, it may be necessary to run non-idempotent code in the
# master before forking. Keep in mind the above disconnect! example
# is idempotent and does not need a guard.
if run_once
# do_something_once_here ...
run_once = false # prevent from firing again
end
# The following is only recommended for memory/DB-constrained
# installations. It is not needed if your system can house
# twice as many worker_processes as you have configured.
#
# # This allows a new master process to incrementally
# # phase out the old master process with SIGTTOU to avoid a
# # thundering herd (especially in the "preload_app false" case)
# # when doing a transparent upgrade. The last worker spawned
# # will then kill off the old master process with a SIGQUIT.
# old_pid = "#{server.config[:pid]}.oldbin"
# if old_pid != server.pid
# begin
# sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
# Process.kill(sig, File.read(old_pid).to_i)
# rescue Errno::ENOENT, Errno::ESRCH
# end
# end
#
# Throttle the master from forking too quickly by sleeping. Due
# to the implementation of standard Unix signal handlers, this
# helps (but does not completely) prevent identical, repeated signals
# from being lost when the receiving process is busy.
# sleep 1
end
after_fork do |server, worker|
# per-process listener ports for debugging/admin/migrations
# addr = "127.0.0.1:#{9293 + worker.nr}"
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
# the following is *required* for Rails + "preload_app true",
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis. TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
end