Skip to content

Instantly share code, notes, and snippets.

@minase
Created April 25, 2014 23:01
Show Gist options
  • Save minase/11306036 to your computer and use it in GitHub Desktop.
Save minase/11306036 to your computer and use it in GitHub Desktop.
# lib/tasks/unicorn.rake
namespace :unicorn do
config = Rails.root + 'config/unicorn.rb'
rackup = Rails.root + 'config.ru'
pid_file = Rails.root + 'tmp/pids/unicorn.pid'
pid = File.exist?(pid_file) ? File.read(pid_file).to_i : nil
desc 'Starting unicorn process'
task :start => :environment do
sh "bundle exec unicorn_rails -D -c #{config} #{rackup}"
end
desc 'Graceful shutdown, waits for workers to finish their current request before finishing'
task :stop => :environment do
send_signal :QUIT, pid
end
desc 'Reexecute the running binary'
task :restart => :environment do
send_signal :USR2, pid
end
desc 'Reloads config file and gracefully restart all workers'
task :reload => :environment do
send_signal :HUP, pid
end
desc 'Increment the number of worker processes by one'
task :increment => :environment do
send_signal :TTIN, pid
end
desc 'Decrement the number of worker processes by one'
task :decrement => :environment do
send_signal :TTOU, pid
end
def send_signal(signal, pid = nil)
Process.kill signal, pid unless pid.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment