Last active
August 29, 2015 14:17
-
-
Save subimage/20366c5b26135596da9a to your computer and use it in GitHub Desktop.
Capistrano rolling restart for passenger / nginx
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
desc "Restarts app servers in a rolling fashion, one by one with wait in between" | |
task :rolling_restart, roles: [:passenger] do | |
servers = find_servers_for_task(current_task) | |
servers.each do |s| | |
run "touch #{current_path}/tmp/restart.txt", hosts: s.host | |
puts "#{s.host} restarting...I'm sleep doe." | |
sleep 45 | |
status = capture "sudo passenger-status; true", hosts: s.host | |
# Sometimes nginx/passenger is a bit wonky and fails to restart? | |
# Not sure if it's because of the load balancer fucking things up or what | |
unless status.match("Requests in top-level queue") | |
puts "Passenger probably shit the bed...restarting nginx" | |
sudo "/etc/init.d/nginx restart; true", hosts: s.host | |
sleep 30 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment