Created
April 25, 2014 23:01
-
-
Save minase/11306036 to your computer and use it in GitHub Desktop.
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
# 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