Last active
January 9, 2021 20:03
-
-
Save mdesantis/1246503 to your computer and use it in GitHub Desktop.
Rails tasks for managing unicorn server instances
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 | |
def unicorn_pid | |
"#{Rails.root}/shared/pids/unicorn.pid" | |
end | |
desc 'start Unicorn production server daemonized (config file: config/unicorn.rb)' | |
task :start => :environment do | |
exec "cd #{Rails.root} && bundle exec unicorn_rails -c config/unicorn.rb -E production -D" | |
end | |
desc 'stop Unicorn production server' | |
task :stop => :environment do | |
exec "kill `cat #{unicorn_pid}`" | |
end | |
desc 'executes `rake unicorn:stop; rake unicorn:start`' | |
task :restart => [:stop, :start] do | |
end | |
desc 'executes a "graceful_stop" (waits for workers to finish their current request before finishing)' | |
task :graceful_stop => :environment do | |
exec "kill -s QUIT `cat #{unicorn_pid}`" | |
end | |
desc 'reexecute the running binary' | |
task :reload => :environment do | |
exec "kill -s USR2 `cat #{unicorn_pid}`" | |
end | |
desc 'reloads config file and gracefully restart all workers, calling a Gem.refresh in order to reload newly installed gems' | |
task :graceful_restart => :environment do | |
exec "kill -s HUP `cat #{unicorn_pid}`" | |
end | |
desc 'gracefully stops workers but keep the master running' | |
task :graceful_restart => :environment do | |
exec "kill -s WINCH `cat #{unicorn_pid}`" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment