Skip to content

Instantly share code, notes, and snippets.

@imajes
Created August 2, 2011 20:05
Show Gist options
  • Select an option

  • Save imajes/1121076 to your computer and use it in GitHub Desktop.

Select an option

Save imajes/1121076 to your computer and use it in GitHub Desktop.
require 'whiskey_disk/helpers'
namespace :unicorn do
# FIXME: could be made a class, cleaner
def pid_file
@pid_file ||= "/var/run/unicorn/village_#{Rails.env}.pid"
end
def pid
if File.exist?(pid_file)
@pid = `cat #{pid_file}`
else
@pid = ''
end
end
def kill_unicorn(signal = 'TERM')
unless pid.empty?
note "Quitting Unicorn.."
system "kill -s #{signal} #{pid}"
note "done\n"
#system "rm #{pid_file}"
end
end
desc "starts unicorn"
task :start => :environment do
note "starting unicorn...."
system "cd #{Rails.root} && bin/unicorn -c #{Rails.root}/config/unicorn.rb -E #{Rails.env} -D"
note "done\n"
end
desc "stops unicorn"
task :stop => :environment do
kill_unicorn 'TERM'
end
desc "tries to gracefully stop unicorn"
task :graceful_stop => :environment do
kill_unicorn 'QUIT'
end
desc "tries to reload unicorn's config"
task :reload => :environment do
kill_unicorn 'USR2'
end
desc "does a reload/restart..."
task :restart => :environment do
Rake::Task['unicorn:stop'].invoke
Rake::Task['unicorn:start'].invoke
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment