Skip to content

Instantly share code, notes, and snippets.

@scaint
Created October 25, 2013 15:21
Show Gist options
  • Save scaint/7156430 to your computer and use it in GitHub Desktop.
Save scaint/7156430 to your computer and use it in GitHub Desktop.
Capistrano 3 tasks for Unicorn
set :unicorn_config, -> { current_path.join('config/unicorn.rb') }
set :unicorn_pid, -> { shared_path.join('tmp/pids/unicorn.pid') }
namespace :unicorn do
desc 'Stop Unicorn'
task :stop do
on roles(:app) do
if test("[ -f #{fetch(:unicorn_pid)} ]")
execute :kill, capture(:cat, fetch(:unicorn_pid))
end
end
end
desc 'Start Unicorn'
task :start do
on roles(:app) do
within current_path do
with rails_env: fetch(:rails_env) do
execute :bundle, "exec unicorn -c #{fetch(:unicorn_config)} -D"
end
end
end
end
desc 'Reload Unicorn without killing master process'
task :reload do
on roles(:app) do
if test("[ -f #{fetch(:unicorn_pid)} ]")
execute :kill, '-s USR2', capture(:cat, fetch(:unicorn_pid))
else
error 'Unicorn process not running'
end
end
end
desc 'Restart Unicorn'
task :restart
before :restart, :stop
before :restart, :start
end
# Usage example:
namespace :deploy do
desc 'Restart application'
task :restart
before :restart, 'unicorn:restart'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment