Skip to content

Instantly share code, notes, and snippets.

@ncdc
Last active April 11, 2016 19:08
Show Gist options
  • Save ncdc/6294975 to your computer and use it in GitHub Desktop.
Save ncdc/6294975 to your computer and use it in GitHub Desktop.
Update OpenShift gear DNS and server_identity entries after a devenv gets a new IP address and DNS name (instance stop, instance start)

Save fixdns.rb to your devenv, e.g to ~. Run it like this:

/var/www/openshift/broker/script/rails r ~/fixdns.rb <login>

Also, run this to fix /etc/openshift/port-proxy.cfg:

ip=$(facter ipaddress)
sed -i "s,bind 10\.[0-9.]\+:,bind $ip:," /etc/openshift/port-proxy.cfg
local_ip = `curl http://169.254.169.254/latest/meta-data/local-ipv4 2>/dev/null`
public_ip = `curl http://169.254.169.254/latest/meta-data/public-ipv4 2>/dev/null`
new_hostname = `nslookup #{public_ip} | grep 'name =' | grep -o 'ec2.*'`[0..-3]
new_server_identity = `hostname`.chomp
dns = OpenShift::DnsService.instance
user = CloudUser.find_by_identity(ARGV[0])
user.domains.each do |domain|
domain.applications.each do |app|
app.group_instances.each do |gi|
gi.gears.each do |g|
g.server_identity = new_server_identity
dns.modify_application(g.name, domain.canonical_namespace, new_hostname)
g.port_interfaces.each do |pi|
pi.external_address = local_ip
end
end
end
app.save
end
end
dns.publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment