Created
August 25, 2015 09:40
-
-
Save ssig33/4aafe9bb6e3eea27c5dd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'bundler' | |
Bundler.require | |
API_KEY = "" | |
CF_API_KEY = '' | |
exit unless Time.now.hour == 3 or Time.now.hour == 15 | |
heroku = PlatformAPI.connect_oauth(API_KEY) | |
cf = CloudFlare::connection(CF_API_KEY, '[email protected]') | |
pairs = { | |
"kanekure.ssig33.com" => ['kanekure', 'kanekure2'], | |
"music.ssig33.com" => ['ssig33-music', 'ssig33-music2'], | |
"ssig33.com" => ['ssig33-site', 'ssig33-site2'] | |
} | |
pairs.each do |hostname, pair| | |
now = nil | |
pair.each_with_index{|host, i| | |
now = i if heroku.domain.list(host).count == 2 | |
} | |
now = 0 if now == nil | |
puts "Now #{hostname}'s Active == #{pair[now]}" | |
old_heroku = pair[now] | |
new_heroku = pair.reject{|x| x == pair[now]}.first | |
domain_name = hostname | |
heroku.domain.delete(old_heroku, domain_name) rescue nil | |
heroku.domain.create(new_heroku, {"hostname" => domain_name}) | |
rec_id = nil | |
cf.rec_load_all("ssig33.com")['response']['recs']['objs'].each do |obj| | |
rec_id = obj['rec_id'] if obj['name'] == domain_name and obj['type'] == 'CNAME' | |
end | |
puts "CF Record ID == #{rec_id}" | |
cf.rec_edit("ssig33.com", 'CNAME', rec_id, domain_name, "#{new_heroku}.herokuapp.com", 1) | |
end | |
system "wget http://ssig33.com > /dev/null" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure if anything in here is sensitive, but keep in mind this is publicly listed.