Created
January 22, 2014 03:36
-
-
Save jun1st/8553105 to your computer and use it in GitHub Desktop.
restart 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
namespace :unicorn do | |
task :environment do | |
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid" | |
set :unicorn_config, "#{current_path}/config/unicorn.rb" | |
end | |
def start_unicorn | |
within current_path do | |
execute :bundle, :exec, :unicorn, "-c #{fetch(:unicorn_config)} -E production -D" | |
end | |
end | |
def stop_unicorn | |
execute :kill, "-s QUIT $(< #{fetch(:unicorn_pid)})" | |
end | |
def reload_unicorn | |
execute :kill, "-s USR2 $(< #{fetch(:unicorn_pid)})" | |
end | |
def force_stop_unicorn | |
execute :kill, "$(< #{fetch(:unicorn_pid)})" | |
end | |
desc "Start unicorn server" | |
task :start => :environment do | |
on roles(:app) do | |
start_unicorn | |
end | |
end | |
desc "Stop unicorn server gracefully" | |
task :stop => :environment do | |
on roles(:app) do | |
stop_unicorn | |
end | |
end | |
desc "Restart unicorn server gracefully" | |
task :restart => :environment do | |
on roles(:app) do | |
if test("[ -f #{fetch(:unicorn_pid)} ]") | |
reload_unicorn | |
else | |
start_unicorn | |
end | |
end | |
end | |
desc "Stop unicorn server immediately" | |
task :force_stop => :environment do | |
on roles(:app) do | |
force_stop_unicorn | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment