From cc498d71c2836e3404f00ca8804199e25af3f900 Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 23 Feb 2017 21:54:19 +0630 Subject: [PATCH 1/6] Cap Setup --- .gitignore | 4 +- Capfile | 47 ++++++++++++++++++++++ Gemfile | 8 ++++ Gemfile.lock | 30 ++++++++++++++- config/database.yml | 4 +- config/deploy.rb | 61 +++++++++++++++++++++++++++++ config/deploy/production.rb | 77 +++++++++++++++++++++++++++++++++++++ 7 files changed, 228 insertions(+), 3 deletions(-) create mode 100644 Capfile create mode 100644 config/deploy.rb create mode 100644 config/deploy/production.rb diff --git a/.gitignore b/.gitignore index bab620d..28d4931 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,8 @@ /tmp/* !/log/.keep !/tmp/.keep - +/ssh +/config/database.yml +/config/secrets.yml # Ignore Byebug command history file. .byebug_history diff --git a/Capfile b/Capfile new file mode 100644 index 0000000..a132828 --- /dev/null +++ b/Capfile @@ -0,0 +1,47 @@ +# Load DSL and set up stages +require "capistrano/setup" + +# Include default deployment tasks +require "capistrano/deploy" + +# Load the SCM plugin appropriate to your project: +# +# require "capistrano/scm/hg" +# install_plugin Capistrano::SCM::Hg +# or +# require "capistrano/scm/svn" +# install_plugin Capistrano::SCM::Svn +# or +require "capistrano/scm/git" +install_plugin Capistrano::SCM::Git + +# Include tasks from other gems included in your Gemfile +# +# For documentation on these, see for example: +# +# https://github.com/capistrano/rvm +# https://github.com/capistrano/rbenv +# https://github.com/capistrano/chruby +# https://github.com/capistrano/bundler +# https://github.com/capistrano/rails +# https://github.com/capistrano/passenger +# +# require "capistrano/rvm" +# require "capistrano/rbenv" +# require "capistrano/chruby" +# require "capistrano/bundler" +# require "capistrano/rails/assets" +# require "capistrano/rails/migrations" +# require "capistrano/passenger" + +require 'capistrano/rails' +require 'capistrano/passenger' + +require 'capistrano/rbenv' +set :rbenv_type, :user +set :rbenv_ruby, '2.3.3' + + + +# Load custom tasks from `lib/capistrano/tasks` if you have any defined +Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r } diff --git a/Gemfile b/Gemfile index 7b7be0b..5649d49 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,12 @@ gem 'bootstrap-multiselect-rails' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platform: :mri + gem 'capistrano' + gem 'capistrano-bundler' + gem 'capistrano-rails' + gem 'capistrano-rbenv' + + end group :development do @@ -58,3 +64,5 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] + + diff --git a/Gemfile.lock b/Gemfile.lock index 7dc7332..ecf5798 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,12 +38,30 @@ GEM i18n (~> 0.7) minitest (~> 5.1) tzinfo (~> 1.1) + airbrussh (1.1.2) + sshkit (>= 1.6.1, != 1.7.0) arel (7.1.4) bcrypt (3.1.11) bootstrap-multiselect-rails (0.9.9) rails (>= 4.0.0) builder (3.2.3) byebug (9.0.6) + capistrano (3.7.2) + airbrussh (>= 1.0.0) + capistrano-harrow + i18n + rake (>= 10.0.0) + sshkit (>= 1.9.0) + capistrano-bundler (1.2.0) + capistrano (~> 3.1) + sshkit (~> 1.2) + capistrano-harrow (0.5.3) + capistrano-rails (1.2.2) + capistrano (~> 3.1) + capistrano-bundler (~> 1.1) + capistrano-rbenv (2.1.0) + capistrano (~> 3.1) + sshkit (~> 1.3) coffee-rails (4.2.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.2.x) @@ -101,6 +119,9 @@ GEM mini_portile2 (2.1.0) minitest (5.10.1) multi_json (1.12.1) + net-scp (1.2.1) + net-ssh (>= 2.6.5) + net-ssh (4.1.0) nio4r (1.2.1) nokogiri (1.7.0.1) mini_portile2 (~> 2.1.0) @@ -161,6 +182,9 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + sshkit (1.12.0) + net-scp (>= 1.1.2) + net-ssh (>= 2.8.0) thor (0.19.4) thread_safe (0.3.5) tilt (2.0.5) @@ -190,6 +214,10 @@ DEPENDENCIES bcrypt (~> 3.1.7) bootstrap-multiselect-rails byebug + capistrano + capistrano-bundler + capistrano-rails + capistrano-rbenv coffee-rails (~> 4.2) devise devise_uid @@ -211,4 +239,4 @@ DEPENDENCIES web-console BUNDLED WITH - 1.13.7 + 1.14.3 diff --git a/config/database.yml b/config/database.yml index 699bc9c..0abb747 100644 --- a/config/database.yml +++ b/config/database.yml @@ -23,4 +23,6 @@ test: production: <<: *default - database: db/production.sqlite3 + database: nemo + username: deploy + password: OU771o3ja3Hn4$r diff --git a/config/deploy.rb b/config/deploy.rb new file mode 100644 index 0000000..26dc14f --- /dev/null +++ b/config/deploy.rb @@ -0,0 +1,61 @@ +# config valid only for current version of Capistrano +lock "3.7.2" + +set :application, "nemo_encoder" +set :repo_url, "git@bitbucket.org:code2lab/nemo_encoder.git" + + +#set :branch, 'master' +# Default deploy_to directory is /var/www/my_app_name +set :deploy_user, 'ubuntu' + +# setup rbenv. +set :rbenv_type, :global +set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" +set :rbenv_map_bins, %w{rake gem bundle ruby rails} + +# how many old releases do we want to keep, not much +set :keep_releases, 5 + +# files we want symlinking to specific entries in shared +set :linked_files, %w{config/database.yml config/secrets.yml} + +# dirs we want symlinking to shared +set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} + +# what specs should be run before deployment is allowed to +# continue, see lib/capistrano/tasks/run_tests.cap +set :tests, [] +#set :pty, true +set :pty, true + + + + +# Default branch is :master +# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp + +# Default deploy_to directory is /var/www/my_app_name +# set :deploy_to, "/var/www/my_app_name" + +# Default value for :format is :airbrussh. +# set :format, :airbrussh + +# You can configure the Airbrussh format using :format_options. +# These are the defaults. +# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto + +# Default value for :pty is false +# set :pty, true + +# Default value for :linked_files is [] +# append :linked_files, "config/database.yml", "config/secrets.yml" + +# Default value for linked_dirs is [] +# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system" + +# Default value for default_env is {} +# set :default_env, { path: "/opt/ruby/bin:$PATH" } + +# Default value for keep_releases is 5 +# set :keep_releases, 5 diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 0000000..e3fba6c --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,77 @@ +# server-based syntax +# ====================== +# Defines a single server with a list of roles and multiple properties. +# You can define all roles on a single server, or split them: + +# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value +# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value +# server "db.example.com", user: "deploy", roles: %w{db} + +set :stage, :production +set :server_name, "svr.nemo.host" +# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value +# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value +# server "db.example.com", user: "deploy", roles: %w{db} +set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}" + + +server 'ec2-54-169-212-254.ap-southeast-1.compute.amazonaws.com', user: 'ubuntu', roles: %w{web app db}, primary: true +ssh_options[:keys] = %w(ssh/nemo.pem) + +set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}" +set :rbenv_ruby, '2.3.1' +set :rails_env, :production + +set :unicorn_worker_count, 5 + + +# role-based syntax +# ================== + +# Defines a role with one or multiple servers. The primary server in each +# group is considered to be the first unless any hosts have the primary +# property set. Specify the username and a domain or IP for the server. +# Don't use `:all`, it's a meta role. + +# role :app, %w{deploy@example.com}, my_property: :my_value +# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value +# role :db, %w{deploy@example.com} + + + +# Configuration +# ============= +# You can set any configuration variable like in config/deploy.rb +# These variables are then only loaded and set in this stage. +# For available Capistrano configuration variables see the documentation page. +# http://capistranorb.com/documentation/getting-started/configuration/ +# Feel free to add new variables to customise your setup. + + + +# Custom SSH Options +# ================== +# You may pass any option but keep in mind that net/ssh understands a +# limited set of options, consult the Net::SSH documentation. +# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start +# +# Global options +# -------------- +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# +# The server-based syntax can be used to override options: +# ------------------------------------ +# server "example.com", +# user: "user_name", +# roles: %w{web app}, +# ssh_options: { +# user: "user_name", # overrides user setting above +# keys: %w(/home/user_name/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(publickey password) +# # password: "please use keys" +# } From b9f47dda994674fd88d8d56774b7efae4b45cd2f Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 23 Feb 2017 21:57:36 +0630 Subject: [PATCH 2/6] insert database.yml to gitignore --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 28d4931..a48995b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,7 @@ !/log/.keep !/tmp/.keep /ssh -/config/database.yml -/config/secrets.yml + # Ignore Byebug command history file. .byebug_history +config/database.yml\nconfig/secrets.yml From 7b5f477cb37bf62db033112d24f5d3e4520bac9b Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 23 Feb 2017 22:24:19 +0630 Subject: [PATCH 3/6] update Gemfile --- Capfile | 2 +- Gemfile | 8 +++++--- config/deploy/production.rb | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Capfile b/Capfile index a132828..dcdef25 100644 --- a/Capfile +++ b/Capfile @@ -35,7 +35,7 @@ install_plugin Capistrano::SCM::Git # require "capistrano/passenger" require 'capistrano/rails' -require 'capistrano/passenger' +#require 'capistrano/passenger' require 'capistrano/rbenv' set :rbenv_type, :user diff --git a/Gemfile b/Gemfile index 5649d49..abbc6c5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' + # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.0.0', '>= 5.0.0.1' # Use sqlite3 as the database for Active Record @@ -15,11 +16,12 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby - +gem 'unicorn' +gem 'execjs' +gem 'therubyracer' platform :ruby do gem 'pg' end - # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks @@ -37,7 +39,7 @@ gem 'jbuilder', '~> 2.5' gem 'devise' gem 'devise_uid' gem 'bcrypt', '~> 3.1.7' -gem 'simple_form' +gem 'simple_form' gem 'kaminari' gem 'to_csv-rails' gem 'bootstrap-multiselect-rails' diff --git a/config/deploy/production.rb b/config/deploy/production.rb index e3fba6c..3f988be 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -16,7 +16,11 @@ set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}" server 'ec2-54-169-212-254.ap-southeast-1.compute.amazonaws.com', user: 'ubuntu', roles: %w{web app db}, primary: true -ssh_options[:keys] = %w(ssh/nemo.pem) +set :ssh_options, { + keys: %w(/home/deploy/nemo_encoder/ssh/nemo.pem), + forward_agent: false, + user: 'ubuntu' +} set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}" set :rbenv_ruby, '2.3.1' From 65b5b5d8581971c14b6121bf9cd327ed58bf4ccf Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 23 Feb 2017 22:34:22 +0630 Subject: [PATCH 4/6] Gemfile.lock update --- Gemfile.lock | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ecf5798..f465ff7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,7 +85,7 @@ GEM ffi (1.9.17) globalid (0.3.7) activesupport (>= 4.1.0) - i18n (0.7.0) + i18n (0.8.0) jbuilder (2.6.1) activesupport (>= 3.0.0, < 5.1) multi_json (~> 1.2) @@ -105,6 +105,8 @@ GEM activerecord kaminari-core (= 1.0.1) kaminari-core (1.0.1) + kgio (2.11.0) + libv8 (3.16.14.17-x86_64-linux) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -154,10 +156,12 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + raindrops (0.17.0) rake (12.0.0) rb-fsevent (0.9.8) rb-inotify (0.9.7) ffi (>= 0.5.0) + ref (2.0.0) responders (2.3.0) railties (>= 4.2.0, < 5.1) sass (3.4.23) @@ -170,7 +174,7 @@ GEM simple_form (3.4.0) actionpack (> 4, < 5.1) activemodel (> 4, < 5.1) - spring (2.0.0) + spring (2.0.1) activesupport (>= 4.2) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) @@ -185,9 +189,12 @@ GEM sshkit (1.12.0) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) + therubyracer (0.12.3) + libv8 (~> 3.16.14.15) + ref thor (0.19.4) thread_safe (0.3.5) - tilt (2.0.5) + tilt (2.0.6) to_csv-rails (0.1.5) turbolinks (5.0.1) turbolinks-source (~> 5) @@ -196,7 +203,10 @@ GEM thread_safe (~> 0.1) uglifier (3.0.4) execjs (>= 0.3.0, < 3) - warden (1.2.6) + unicorn (5.2.0) + kgio (~> 2.6) + raindrops (~> 0.7) + warden (1.2.7) rack (>= 1.0) web-console (3.4.0) actionview (>= 5.0) @@ -221,6 +231,7 @@ DEPENDENCIES coffee-rails (~> 4.2) devise devise_uid + execjs jbuilder (~> 2.5) jquery-rails kaminari @@ -232,10 +243,12 @@ DEPENDENCIES simple_form spring spring-watcher-listen (~> 2.0.0) + therubyracer to_csv-rails turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) + unicorn web-console BUNDLED WITH From db0d28107b80adc505ca9dd19df20c8aa888ab81 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 24 Feb 2017 00:18:22 +0630 Subject: [PATCH 5/6] update environments/production.rb add unicorn.rb, nemo.sh --- Gemfile | 1 + config/deploy.rb | 2 +- config/deploy/production.rb.save | 61 +++++++++++++++++++++++++++ config/environments/production.rb | 4 +- config/nemo.sh | 69 +++++++++++++++++++++++++++++++ config/unicorn.rb | 39 +++++++++++++++++ 6 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 config/deploy/production.rb.save create mode 100644 config/nemo.sh create mode 100644 config/unicorn.rb diff --git a/Gemfile b/Gemfile index abbc6c5..4fb97ed 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,7 @@ gem 'coffee-rails', '~> 4.2' # gem 'therubyracer', platforms: :ruby gem 'unicorn' gem 'execjs' +gem 'rack', '~> 2.0.0' gem 'therubyracer' platform :ruby do gem 'pg' diff --git a/config/deploy.rb b/config/deploy.rb index 26dc14f..5ec9067 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -21,7 +21,7 @@ set :keep_releases, 5 set :linked_files, %w{config/database.yml config/secrets.yml} # dirs we want symlinking to shared -set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} +set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system pids sockets} # what specs should be run before deployment is allowed to # continue, see lib/capistrano/tasks/run_tests.cap diff --git a/config/deploy/production.rb.save b/config/deploy/production.rb.save new file mode 100644 index 0000000..140fc76 --- /dev/null +++ b/config/deploy/production.rb.save @@ -0,0 +1,61 @@ +# server-based syntax +# ====================== +# Defines a single server with a list of roles and multiple properties. +# You can define all roles on a single server, or split them: + +# server "example.com", user: "deploy", roles: %w{app db web}, my_property: :my_value +# server "example.com", user: "deploy", roles: %w{app web}, other_property: :other_value +# server "db.example.com", user: "deploy", roles: %w{db} +/deploy/production.rb: + + +# role-based syntax +# ================== + +# Defines a role with one or multiple servers. The primary server in each +# group is considered to be the first unless any hosts have the primary +# property set. Specify the username and a domain or IP for the server. +# Don't use `:all`, it's a meta role. + +# role :app, %w{deploy@example.com}, my_property: :my_value +# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value +# role :db, %w{deploy@example.com} + + + +# Configuration +# ============= +# You can set any configuration variable like in config/deploy.rb +# These variables are then only loaded and set in this stage. +# For available Capistrano configuration variables see the documentation page. +# http://capistranorb.com/documentation/getting-started/configuration/ +# Feel free to add new variables to customise your setup. + + + +# Custom SSH Options +# ================== +# You may pass any option but keep in mind that net/ssh understands a +# limited set of options, consult the Net::SSH documentation. +# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start +# +# Global options +# -------------- +# set :ssh_options, { +# keys: %w(/home/rlisowski/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(password) +# } +# +# The server-based syntax can be used to override options: +# ------------------------------------ +# server "example.com", +# user: "user_name", +# roles: %w{web app}, +# ssh_options: { +# user: "user_name", # overrides user setting above +# keys: %w(/home/user_name/.ssh/id_rsa), +# forward_agent: false, +# auth_methods: %w(publickey password) +# # password: "please use keys" +# } diff --git a/config/environments/production.rb b/config/environments/production.rb index 151e852..7817a04 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -23,7 +23,7 @@ Rails.application.configure do # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false + config.assets.compile = true # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb @@ -55,7 +55,7 @@ Rails.application.configure do # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "nemo_encoder_#{Rails.env}" - config.action_mailer.perform_caching = false + config.action_mailer.perform_caching = true # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. diff --git a/config/nemo.sh b/config/nemo.sh new file mode 100644 index 0000000..3a84751 --- /dev/null +++ b/config/nemo.sh @@ -0,0 +1,69 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: unicorn +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts the unicorn app server +# Description: starts unicorn using start-stop-daemon +### END INIT INFO + +set -e +USAGE="Usage: $0 " + +# app settings +USER="ubuntu" +APP_NAME="nemo_encoder_production" +APP_ROOT="/home/$USER/apps/$APP_NAME/current" +ENV="production" + +# environment settings +PATH="/home/$USER/.rbenv/shims:/home/$USER/.rbenv/bin:$PATH" +CMD="/home/$USER/.rbenv/shims/unicorn_rails -c $APP_ROOT/config/unicorn.rb -E $ENV -D" +PID="$APP_ROOT/pids/unicorn.nemo.pid" +OLD_PID="$PID.oldbin" + + +cd $APP_ROOT || exit 1 + +sig () { + test -s "$PID" && kill -$1 `cat $PID` +} + +oldsig () { + test -s $OLD_PID && kill -$1 `cat $OLD_PID` +} + + +case $1 in + start) + sig 0 && echo >&2 "Already running" && exit 0 + echo "Starting $APP_NAME" + su - $USER -c "$CMD" + ;; + stop) + echo "Stopping $APP_NAME" + sig QUIT && exit 0 + echo >&2 "Not running" + ;; + force-stop) + echo "Force stopping $APP_NAME" + sig TERM && exit 0 + echo >&2 "Not running" + ;; + restart|reload|upgrade) + sig USR2 && echo "reloaded $APP_NAME" && exit 0 + echo >&2 "Couldn't reload, starting '$CMD' instead" + $CMD + ;; + rotate) + sig USR1 && echo rotated logs OK && exit 0 + echo >&2 "Couldn't rotate logs" && exit 1 + ;; + *) + echo >&2 $USAGE + exit 1 + ;; +esac + diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..ba6070d --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,39 @@ +root=File.expand_path(File.dirname(__FILE__) + '/..') +#shared_dir="#{root}/shared" +working_directory root +pid "#{root}/pids/unicorn.nemo.pid" +stderr_path "#{root}/log/unicorn.stderr.log" +stdout_path "#{root}/log/unicorn.stdout.log" +listen "#{root}/sockets/unicorn.nemo.sock", :backlog => 64 +listen(8081, backlog: 64) if ENV['RAILS_ENV'] == 'production' +worker_processes 2 +preload_app true +timeout 30 + + +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! + + ## + # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and + # immediately start loading up a new version of itself (loaded with a new + # version of our app). When this new Unicorn is completely loaded + # it will begin spawning workers. The first worker spawned will check to + # see if an .oldbin pidfile exists. If so, this means we've just booted up + # a new Unicorn and need to tell the old one that it can now die. To do so + # we send it a QUIT. + # + # Using this method we get 0 downtime deploys. + + old_pid = "#{root}/pids/unicorn.nemo.pid.oldbin" + if File.exists?(old_pid) && server.pid != old_pid + begin + Process.kill("QUIT", File.read(old_pid).to_i) + rescue Errno::ENOENT, Errno::ESRCH + # someone else did our job for us + end + end +end + From 562236def7ff2414d4056c46880f3a80e9d77208 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 24 Feb 2017 00:48:04 +0630 Subject: [PATCH 6/6] update --- Gemfile.lock | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f465ff7..9964444 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,8 +85,8 @@ GEM ffi (1.9.17) globalid (0.3.7) activesupport (>= 4.1.0) - i18n (0.8.0) - jbuilder (2.6.1) + i18n (0.8.1) + jbuilder (2.6.2) activesupport (>= 3.0.0, < 5.1) multi_json (~> 1.2) jquery-rails (4.2.2) @@ -106,7 +106,7 @@ GEM kaminari-core (= 1.0.1) kaminari-core (1.0.1) kgio (2.11.0) - libv8 (3.16.14.17-x86_64-linux) + libv8 (3.16.14.17) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -129,7 +129,7 @@ GEM mini_portile2 (~> 2.1.0) orm_adapter (0.5.0) pg (0.19.0) - puma (3.6.2) + puma (3.7.1) rack (2.0.1) rack-test (0.6.3) rack (>= 1.0) @@ -159,7 +159,7 @@ GEM raindrops (0.17.0) rake (12.0.0) rb-fsevent (0.9.8) - rb-inotify (0.9.7) + rb-inotify (0.9.8) ffi (>= 0.5.0) ref (2.0.0) responders (2.3.0) @@ -193,7 +193,7 @@ GEM libv8 (~> 3.16.14.15) ref thor (0.19.4) - thread_safe (0.3.5) + thread_safe (0.3.6) tilt (2.0.6) to_csv-rails (0.1.5) turbolinks (5.0.1) @@ -213,7 +213,7 @@ GEM activemodel (>= 5.0) debug_inspector railties (>= 5.0) - websocket-driver (0.6.4) + websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) @@ -238,6 +238,7 @@ DEPENDENCIES listen (~> 3.0.5) pg puma (~> 3.0) + rack (~> 2.0.0) rails (~> 5.0.0, >= 5.0.0.1) sass-rails (~> 5.0) simple_form