update to capistrano3

This commit is contained in:
r888888888
2015-08-19 14:12:55 -07:00
parent 657846732d
commit e669b66395
12 changed files with 267 additions and 187 deletions

View File

@@ -1,165 +1,8 @@
set :stages, %w(production development staging)
set :default_stage, "staging"
set :unicorn_env, defer {stage}
require 'capistrano/ext/multistage'
require 'bundler/capistrano'
set :bundle_flags, "--deployment --quiet --binstubs --shebang ruby"
set :default_environment, {
"PATH" => '$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH'
}
set :whenever_command, "bundle exec whenever"
set :whenever_environment, defer {stage}
require 'whenever/capistrano'
require 'securerandom'
set :secret_1, SecureRandom.base64(32)
set :secret_2, SecureRandom.base64(32)
set :application, "danbooru"
set :repository, "git://github.com/r888888888/danbooru.git"
set :repo_url, "git://github.com/r888888888/danbooru.git"
set :scm, :git
set :user, "danbooru"
set :deploy_to, "/var/www/danbooru2"
require 'capistrano-unicorn'
default_run_options[:pty] = true
namespace :local_config do
desc "Create the shared config directory"
task :setup_shared_directory do
run "mkdir -p #{deploy_to}/shared/config"
end
desc "Initialize the secrets"
task :setup_secrets do
run "mkdir -p ~/.danbooru"
run "if [[ ! -e ~/.danbooru/session_secret_key ]] ; then echo '#{secret_1}' > ~/.danbooru/session_secret_key ; fi"
run "if [[ ! -e ~/.danbooru/secret_token ]] ; then echo '#{secret_2}' > ~/.danbooru/secret_token ; fi"
run "chmod 600 ~/.danbooru/secret_token"
run "chmod 600 ~/.danbooru/session_secret_key"
run "chown -R #{user}:#{user} ~/.danbooru"
end
desc "Initialize local config files"
task :setup_local_files do
run "curl -s https://raw.githubusercontent.com/r888888888/danbooru/master/script/install/danbooru_local_config.rb.templ > #{deploy_to}/shared/config/danbooru_local_config.rb"
run "curl -s https://raw.githubusercontent.com/r888888888/danbooru/master/script/install/database.yml.templ > #{deploy_to}/shared/config/database.yml"
end
desc "Link the local config files"
task :link_local_files do
run "ln -s #{deploy_to}/shared/config/danbooru_local_config.rb #{release_path}/config/danbooru_local_config.rb"
run "ln -s #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
run "ln -s #{deploy_to}/shared/config/newrelic.yml #{release_path}/config/newrelic.yml"
end
end
namespace :data do
task :setup_directories do
run "mkdir -p #{deploy_to}/shared/data"
run "mkdir #{deploy_to}/shared/data/preview"
run "mkdir #{deploy_to}/shared/data/sample"
end
task :link_directories do
run "rm -f #{release_path}/public/data"
run "ln -s #{deploy_to}/shared/data #{release_path}/public/data"
run "rm -f #{release_path}/public/images/advertisements"
run "ln -s #{deploy_to}/shared/advertisements #{release_path}/public/images/advertisements"
run "mkdir -p #{release_path}/public/cache"
run "mkdir -p #{deploy_to}/shared/system/cache"
run "touch #{deploy_to}/shared/system/cache/tags.json"
run "ln -s #{deploy_to}/shared/system/cache/tags.json #{release_path}/public/cache/tags.json"
run "touch #{deploy_to}/shared/system/cache/tags.json.gz"
run "ln -s #{deploy_to}/shared/system/cache/tags.json.gz #{release_path}/public/cache/tags.json.gz"
end
end
desc "Change ownership of common directory to user"
task :reset_ownership_of_common_directory do
sudo "chown -R #{user}:#{user} #{deploy_to}"
end
namespace :deploy do
namespace :web do
desc "Present a maintenance page to visitors."
task :disable do
maintenance_html_path = "#{current_path}/public/maintenance.html.bak"
run "if [ -e #{maintenance_html_path} ] ; then mv #{maintenance_html_path} #{current_path}/public/maintenance.html ; fi"
end
desc "Makes the application web-accessible again."
task :enable do
maintenance_html_path = "#{current_path}/public/maintenance.html"
run "if [ -e #{maintenance_html_path} ] ; then mv #{maintenance_html_path} #{current_path}/public/maintenance.html.bak ; fi"
end
end
namespace :nginx do
desc "Shut down Nginx"
task :stop do
sudo "/etc/init.d/nginx stop"
end
desc "Start Nginx"
task :start do
sudo "/etc/init.d/nginx start"
end
end
desc "Precompiles assets"
task :precompile_assets do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
# run "cd #{current_path}/public/assets; cp application-*.js application.js ; cp application-*.css application.css"
end
end
namespace :delayed_job do
desc "Start delayed_job process"
task :start, :roles => :app do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec ruby script/delayed_job --queues=default,`hostname` -n 2 start"
end
desc "Stop delayed_job process"
task :stop, :roles => :app do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec ruby script/delayed_job stop"
end
desc "Restart delayed_job process"
task :restart, :roles => :app do
find_and_execute_task("delayed_job:stop")
find_and_execute_task("delayed_job:start")
end
task :kill, :roles => :app do
procs = capture("ps -A -o pid,command").split(/\r\n|\r|\n/).grep(/delayed_job/).map(&:to_i)
if procs.any?
run "for i in #{procs.join(' ')} ; do kill -s TERM $i ; done"
end
end
end
after "deploy:setup", "reset_ownership_of_common_directory"
after "deploy:setup", "local_config:setup_shared_directory"
after "deploy:setup", "local_config:setup_local_files"
after "deploy:setup", "data:setup_directories"
after "deploy:setup", "local_config:setup_secrets"
after "deploy:create_symlink", "local_config:link_local_files"
after "deploy:create_symlink", "data:link_directories"
after "deploy:start", "delayed_job:start"
after "deploy:stop", "delayed_job:stop"
before "deploy:update", "deploy:web:disable"
after "deploy:update", "delayed_job:restart"
after "deploy:update", "deploy:migrate"
after "deploy:update", "unicorn:reload"
after "deploy:update", "unicorn:restart"
after "deploy:update", "deploy:precompile_assets"
after "deploy:update", "deploy:web:enable"
after "delayed_job:stop", "delayed_job:kill"
set :rbenv_ruby, "2.1.5"
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle')

View File

@@ -1 +1 @@
server "localhost", :web, :app, :db, :primary => true
server "localhost", :roles => %w(web app db), :primary => true

View File

@@ -1,3 +1,3 @@
set :user, "albert"
server "sonohara.donmai.us", :web, :app, :db, :primary => true
server "hijiribe.donmai.us", :web, :app
server "sonohara.donmai.us", :roles => %w(web app db), :primary => true, :user => "albert"
server "hijiribe.donmai.us", :roles => %w(web app), :user => "albert"

View File

@@ -1 +1 @@
server "testbooru.donmai.us", :web, :app, :db, :primary => true
server "testbooru.donmai.us", :roles => %w(web app db), :primary => true, :user => "danbooru"

View File

@@ -38,4 +38,6 @@ Rails.application.configure do
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.eager_load = false
end

View File

@@ -77,4 +77,5 @@ Rails.application.configure do
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.eager_load = true
end

View File

@@ -0,0 +1,81 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like
# NGINX, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :error
# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# 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.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.eager_load = true
end

View File

@@ -39,4 +39,6 @@ Rails.application.configure do
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
config.eager_load = false
end

View File

@@ -1,7 +1,7 @@
# Ensure the agent is started using Unicorn.
# This is needed when using Unicorn and preload_app is not set to true.
# See https://newrelic.com/docs/ruby/no-data-with-unicorn
if defined? Unicorn
if defined? ::NewRelic
::NewRelic::Agent.manual_start()
::NewRelic::Agent.after_fork(:force_reconnect => true)
end