Skip to content

Instantly share code, notes, and snippets.

@agmcleod
Created March 25, 2015 19:30
Show Gist options
  • Save agmcleod/913939e1de1deb7e35a9 to your computer and use it in GitHub Desktop.
Save agmcleod/913939e1de1deb7e35a9 to your computer and use it in GitHub Desktop.
# config valid only for current version of Capistrano
lock '3.3.5'
set :application, 'desert'
set :repo_url, '[email protected]:agmcleod/dune.git'
set :assets_roles, [:web, :app]
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, '/var/www/apps/desert'
set :linked_files, %w{config/database.yml config/secrets.yml config/application.yml}
set :linked_dirs, %w(tmp/pids tmp/sockets)
set :keep_releases, 5
namespace :deploy do
def unicorn_start_cmd
"cd #{release_path} && bundle exec unicorn -c unicorn/config.rb -E #{rails_env} -D"
end
task :restart do
on roles(:app) do
running = capture("[ -f /var/www/apps/desert/current/tmp/pids/unicorn.pid ] || printf '0'")
restart_command = if running != "0"
old_pid = capture("cat /var/www/apps/desert/current/tmp/pids/unicorn.pid")
"kill -USR2 #{old_pid}; sleep 5; kill -QUIT #{old_pid}"
else
unicorn_start_cmd
end
execute restart_command
end
end
after :deploy, :restart
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment