Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill `cat #{unicorn_pid}`"
end
task :graceful_stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
end
task :reload, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
end
task :restart, :roles => :app, :except => { :no_release => true } do
stop
start
end
end
@plentz

This comment has been minimized.

Copy link

plentz commented Mar 3, 2012

why not change restart to just reload instead of stop,start?

@vvalgis

This comment has been minimized.

Copy link
Owner Author

vvalgis commented Mar 3, 2012

Reload task it's for reread config file, some sort of soft restart. Restart task is for hard restart, added just in case.

@plentz

This comment has been minimized.

Copy link

plentz commented Mar 3, 2012

just made a test here and using reload, it reloaded the app code too. I think it's better(and faster) then the stop/restart process http://unicorn.bogomips.org/SIGNALS.html

@vvalgis

This comment has been minimized.

Copy link
Owner Author

vvalgis commented Mar 3, 2012

If restart as usual, when you deploy for example, then you are right. I use reload task in the most of cases. But sometimes need to use hard reset, in case of server glitches.

@NARKOZ

This comment has been minimized.

Copy link

NARKOZ commented Dec 5, 2012

The letter flag itself is optional: both kill USR2 and kill -s USR2 do the same thing.

@TheKidCoder

This comment has been minimized.

Copy link

TheKidCoder commented Oct 4, 2013

Minor tip, might help speed up a bit. Instead of using ruby backticks for the PID, do it the UNIX way.

run "kill -s USR2 $(< #{unicorn_pid})"
@thiyagarajan

This comment has been minimized.

Copy link

thiyagarajan commented Jun 30, 2014

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.