Merge branch 'fix-4123'
This commit is contained in:
5
Capfile
5
Capfile
@@ -4,6 +4,9 @@ require 'capistrano/setup'
|
|||||||
# Include default deployment tasks
|
# Include default deployment tasks
|
||||||
require 'capistrano/deploy'
|
require 'capistrano/deploy'
|
||||||
|
|
||||||
|
require "capistrano/scm/git"
|
||||||
|
install_plugin Capistrano::SCM::Git
|
||||||
|
|
||||||
# Include tasks from other gems included in your Gemfile
|
# Include tasks from other gems included in your Gemfile
|
||||||
require 'capistrano/rbenv'
|
require 'capistrano/rbenv'
|
||||||
require 'capistrano/rails'
|
require 'capistrano/rails'
|
||||||
@@ -14,5 +17,3 @@ require 'new_relic/recipes'
|
|||||||
|
|
||||||
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
||||||
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
|
||||||
|
|
||||||
after "deploy:updated", "newrelic:notice_deployment"
|
|
||||||
|
|||||||
@@ -2,8 +2,16 @@ set :stages, %w(production development staging)
|
|||||||
set :default_stage, "staging"
|
set :default_stage, "staging"
|
||||||
set :application, "danbooru"
|
set :application, "danbooru"
|
||||||
set :repo_url, "git://github.com/r888888888/danbooru.git"
|
set :repo_url, "git://github.com/r888888888/danbooru.git"
|
||||||
set :scm, :git
|
|
||||||
set :deploy_to, "/var/www/danbooru2"
|
set :deploy_to, "/var/www/danbooru2"
|
||||||
set :rbenv_ruby, "2.5.1"
|
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")
|
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
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
set :user, "danbooru"
|
set :user, "danbooru"
|
||||||
set :rails_env, "production"
|
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 "shima", :roles => %w(web app)
|
||||||
server "saitou", :roles => %w(web app)
|
server "saitou", :roles => %w(web app)
|
||||||
server "oogaki", :roles => %w(worker)
|
server "oogaki", :roles => %w(worker)
|
||||||
|
|
||||||
set :linked_files, fetch(:linked_files, []).push(".env.production")
|
after "deploy:finished", "newrelic:notice_deployment"
|
||||||
set :rbenv_path, "/home/danbooru/.rbenv"
|
|
||||||
|
|||||||
32
lib/capistrano/tasks/app.rake
Normal file
32
lib/capistrano/tasks/app.rake
Normal 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
|
||||||
@@ -1,20 +1,25 @@
|
|||||||
|
# https://bogomips.org/unicorn/SIGNALS.html
|
||||||
namespace :unicorn do
|
namespace :unicorn do
|
||||||
desc "Terminate unicorn processes (blocks until complete)"
|
desc "Terminate unicorn processes (blocks until complete)"
|
||||||
task :terminate do
|
task :terminate do
|
||||||
on roles(:app) do
|
on roles(:app) do
|
||||||
execute "[[ -n $(pgrep -f unicorn) ]] && pgrep -f unicorn | xargs kill -SIGTERM"
|
within current_path do
|
||||||
sleep(5)
|
kill_unicorn("SIGQUIT")
|
||||||
|
sleep(10)
|
||||||
|
kill_unicorn("SIGTERM")
|
||||||
|
sleep(2)
|
||||||
|
kill_unicorn("SIGKILL")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Kills unicorn processes (blocks until complete)"
|
def unicorn_running?
|
||||||
task :kill do
|
test("[ -f #{fetch(:unicorn_pid)} ] && pkill --count --pidfile #{fetch(:unicorn_pid)}")
|
||||||
on roles(:app) do
|
end
|
||||||
execute "[[ -n $(pgrep -f unicorn) ]] && pgrep -f unicorn | xargs kill -SIGKILL"
|
|
||||||
|
def kill_unicorn(signal)
|
||||||
|
if unicorn_running?
|
||||||
|
execute :pkill, "--signal #{signal}", "--pidfile #{fetch(:unicorn_pid)}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
after "deploy:published", "unicorn:terminate"
|
|
||||||
after "deploy:published", "unicorn:kill"
|
|
||||||
after "deploy:published", "unicorn:start"
|
|
||||||
|
|||||||
@@ -19,6 +19,3 @@ namespace :web do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
before "deploy:started", "web:disable"
|
|
||||||
after "deploy:published", "web:enable"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user