Created
October 25, 2013 15:21
-
-
Save scaint/7156430 to your computer and use it in GitHub Desktop.
Capistrano 3 tasks for Unicorn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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