Skip to content

Instantly share code, notes, and snippets.

@aghecht
Created August 12, 2013 18:00
Show Gist options
  • Save aghecht/6213328 to your computer and use it in GitHub Desktop.
Save aghecht/6213328 to your computer and use it in GitHub Desktop.
unicorn config
require "bundler/capistrano"
set :application, "xxx"
set :repository, "xxx"
set :scm, :git
set :branch, "locomotive"
# set :deploy_to "/u/apps/#{application}"
role :web, "xxx" # Your HTTP server, Apache/etc
role :app, "xxx" # This may be the same as your `Web` server
role :db, "xxx", :primary => true # This is where Rails migrations will run
#role :db, "your slave db-server here"
set :user, "xxx"
set :password, "xxx"
# It complained about no tty, so use pty... no profile scripts :(
# http://weblog.jamisbuck.org/2007/10/14/capistrano-2-1
default_run_options[:pty] = true
# Don't show so much! (Log levels: IMPORTANT, INFO, DEBUG, TRACE, MAX_LEVEL)
logger.level = Capistrano::Logger::MAX_LEVEL
# Since we're using pty, load the path ourselves
set :default_environment, {
"PATH" => "/home/app_user/.rbenv/shims:/home/app_user/.rbenv/bin:$PATH;"
}
namespace :deploy do
desc "Zero-downtime restart of Unicorn"
task :restart, roles: :app, :except => { :no_release => true } do
run "kill -s USR2 `cat /var/run/unicorn.pid`"
end
desc "Start Unicorn"
task :start, roles: :app, :except => { :no_release => true } do
run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D"
end
desc "Stop Unicorn"
task :stop, roles: :app, :except => { :no_release => true } do
run "kill -s QUIT `cat /var/run/unicorn.pid`"
end
namespace :assets do
desc <<-DESC
Run the asset precompilation rake task. You can specify the full path \
to the rake executable by setting the rake variable. You can also \
specify additional environment variables to pass to rake via the \
asset_env variable. The defaults are:
set :rake, "rake"
set :rails_env, "production"
set :asset_env, "RAILS_GROUPS=assets"
* only runs if assets have changed (add `-s force_assets=true` to force precompilation)
DESC
task :precompile, :roles => :web, :except => { :no_release => true } do
# Only precompile assets if any assets changed
# http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano/
from = source.next_revision(current_revision)
if fetch(:force_assets, false) || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ lib/assets/ | wc -l").to_i > 0
# Just like original: https://github.com/capistrano/capistrano/blob/master/lib/capistrano/recipes/deploy/assets.rb
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile"
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment