Skip to content

Instantly share code, notes, and snippets.

@khiet
Created April 6, 2014 08:06
Show Gist options
  • Save khiet/10002824 to your computer and use it in GitHub Desktop.
Save khiet/10002824 to your computer and use it in GitHub Desktop.
time = ARGV[0]
dry_run = ARGV[1] == '--dry'
puts "Killing stale servers older than #{time}"
puts "***DRY RUN***" if dry_run
output = `for i in {1..36}; do echo web$i; ssh deploy@web$i.housetrip.com "ps aux | grep [R]ack" | grep -v "#{time}" | awk '{ print $2 }'; done`
server = nil
output.split("\n").each do |line|
if line =~ /web/
server = line
else
next unless server
puts "Executing: ssh deploy@#{server}.housetrip.com 'kill #{line}'"
`ssh deploy@#{server}.housetrip.com 'kill #{line}'` unless dry_run
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment