Skip to content

Instantly share code, notes, and snippets.

@subimage
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subimage/20366c5b26135596da9a to your computer and use it in GitHub Desktop.
Save subimage/20366c5b26135596da9a to your computer and use it in GitHub Desktop.
Capistrano rolling restart for passenger / nginx
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