Merge branch 'fix-4123'

This commit is contained in:
evazion
2019-08-07 22:39:03 -05:00
6 changed files with 65 additions and 20 deletions

View File

@@ -4,6 +4,9 @@ require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
require 'capistrano/rbenv'
require 'capistrano/rails'
@@ -14,5 +17,3 @@ require 'new_relic/recipes'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
after "deploy:updated", "newrelic:notice_deployment"

View File

@@ -2,8 +2,16 @@ set :stages, %w(production development staging)
set :default_stage, "staging"
set :application, "danbooru"
set :repo_url, "git://github.com/r888888888/danbooru.git"
set :scm, :git
set :deploy_to, "/var/www/danbooru2"
set :rbenv_ruby, "2.5.1"
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle')
append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "vendor/bundle"
set :branch, ENV.fetch("branch", "master")
# skip migrations if files in db/migrate weren't modified
set :conditionally_migrate, true
# run migrations on the primary app server
set :migration_role, :app
# how long unicorn:legacy_restart (used by deploy:rolling) waits until killing the old unicorn.
set :unicorn_restart_sleep_time, 10

View File

@@ -1,9 +1,11 @@
set :user, "danbooru"
set :rails_env, "production"
server "kagamihara", :roles => %w(web app db), :primary => true
set :rbenv_path, "/home/danbooru/.rbenv"
append :linked_files, ".env.production"
server "kagamihara", :roles => %w(web app), :primary => true
server "shima", :roles => %w(web app)
server "saitou", :roles => %w(web app)
server "oogaki", :roles => %w(worker)
set :linked_files, fetch(:linked_files, []).push(".env.production")
set :rbenv_path, "/home/danbooru/.rbenv"
after "deploy:finished", "newrelic:notice_deployment"

View File

@@ -0,0 +1,32 @@
namespace :app do
set :rolling_deploy, false
before "deploy:migrate", "app:disable"
after "deploy:published", "app:enable"
task :disable do
if fetch(:rolling_deploy)
# do nothing
else
invoke "web:disable"
invoke "unicorn:terminate"
end
end
task :enable do
if fetch(:rolling_deploy)
invoke "unicorn:legacy_restart"
else
invoke "unicorn:start"
invoke "web:enable"
end
end
end
namespace :deploy do
desc "Deploy a rolling update without taking the site down for maintenance"
task :rolling do
set :rolling_deploy, true
invoke "deploy"
end
end

View File

@@ -1,20 +1,25 @@
# https://bogomips.org/unicorn/SIGNALS.html
namespace :unicorn do
desc "Terminate unicorn processes (blocks until complete)"
task :terminate do
on roles(:app) do
execute "[[ -n $(pgrep -f unicorn) ]] && pgrep -f unicorn | xargs kill -SIGTERM"
sleep(5)
within current_path do
kill_unicorn("SIGQUIT")
sleep(10)
kill_unicorn("SIGTERM")
sleep(2)
kill_unicorn("SIGKILL")
end
end
end
desc "Kills unicorn processes (blocks until complete)"
task :kill do
on roles(:app) do
execute "[[ -n $(pgrep -f unicorn) ]] && pgrep -f unicorn | xargs kill -SIGKILL"
def unicorn_running?
test("[ -f #{fetch(:unicorn_pid)} ] && pkill --count --pidfile #{fetch(:unicorn_pid)}")
end
def kill_unicorn(signal)
if unicorn_running?
execute :pkill, "--signal #{signal}", "--pidfile #{fetch(:unicorn_pid)}"
end
end
end
after "deploy:published", "unicorn:terminate"
after "deploy:published", "unicorn:kill"
after "deploy:published", "unicorn:start"

View File

@@ -19,6 +19,3 @@ namespace :web do
end
end
end
before "deploy:started", "web:disable"
after "deploy:published", "web:enable"