Created
November 2, 2010 21:37
-
-
Save elskwid/660339 to your computer and use it in GitHub Desktop.
Some tasks I'm using with Unicorn
This file contains 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_binary, "/usr/bin/unicorn" | |
set :unicorn_config, "#{current_path}/config/unicorn.rb" | |
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid" | |
namespace :deploy do | |
desc "Start unicorn" | |
task :start, :roles => :app, :except => { :no_release => true } do | |
run "cd #{current_path} && #{try_sudo} bundle exec #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D" | |
end | |
desc "Stop unicorn" | |
task :stop, :roles => :app, :except => { :no_release => true } do | |
unicorn_pid_command(:stop, "kill") | |
end | |
desc "Gracefully stop unicorn" | |
task :graceful_stop, :roles => :app, :except => { :no_release => true } do | |
unicorn_pid_command(:graceful_stop, "kill -s QUIT") | |
end | |
desc "Reload unicorn" | |
task :reload, :roles => :app, :except => { :no_release => true } do | |
unicorn_pid_command(:reload, "kill -s USR2") | |
end | |
desc "Restart unicorn" | |
task :restart, :roles => :app, :except => { :no_release => true } do | |
stop | |
start | |
end | |
end | |
def unicorn_pid_command(task, cmd) | |
cmd = "#{try_sudo} #{cmd} `cat #{unicorn_pid}`" | |
if remote_file_exists?(unicorn_pid) | |
run cmd | |
else | |
puts "Unicorn pidfile doesn't exists so I couldn't run #{task} task: '#{cmd}'" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment