Skip to content

Instantly share code, notes, and snippets.

@dobs
Last active December 29, 2015 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dobs/7602101 to your computer and use it in GitHub Desktop.
Save dobs/7602101 to your computer and use it in GitHub Desktop.
Unicorn + Capistrano 3 + RVM + GIT
set :application, '<%= application %>'
set :repo_url, '<%= repo_url %>'
set :user, '<%= user %>'
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
set :deploy_to, "<%= deploy_to %>"
set :scm, :git
set :format, :pretty
# set :log_level, :debug
# set :pty, true
set :linked_files, %w{config/application.yml config/database.yml}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :keep_releases, 5
namespace :deploy do
desc 'Start application'
task :start do
on roles(:app) do |host|
within current_path do
execute :bundle, :exec, :unicorn_rails, '-c', "#{current_path}/config/unicorn.rb", '-D'
end
end
end
desc 'Stop application'
task :stop do
on roles(:app) do |host|
execute :kill, "`cat #{current_path}/tmp/pids/unicorn.pid`"
end
end
desc 'Gracefully stop application'
task :graceful_stop do
on roles(:app) do |host|
execute :kill, :QUIT, "`cat #{current_path}/tmp/pids/unicorn.pid`"
end
end
desc 'Gracefully reload application'
task :reload do
on roles(:app) do |host|
execute :kill, :USR2, "`cat #{current_path}/tmp/pids/unicorn.pid`"
end
end
desc 'Restart application'
task :restart do
invoke 'deploy:stop'
invoke 'deploy:start'
end
before :start, 'rvm:hook'
after :restart, :clear_cache do
# on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
# end
end
after :finishing, 'deploy:cleanup'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment