Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timani/b228c30a990c3aaf43a3666dae3b7fc8 to your computer and use it in GitHub Desktop.
Save timani/b228c30a990c3aaf43a3666dae3b7fc8 to your computer and use it in GitHub Desktop.
After a 1.7+ opsmanager restarts with a new ip address, this script will update it in the database
#!/bin/bash
# After a 1.7+ opsmanager restarts with a new ip address
# ssh into the opsmanager as 'ubuntu' and
# Run this file from the opsmanager as follows
# sudo su -l postgres < thisfile.sh >
# Get the current public ip or hostname from aws metadata
HN=$(curl http://169.254.169.254/latest/meta-data/public-hostname)
if [[ -z ${HN} ]];then
HN=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
fi
# get the current hostname
psql -d tempest_production -c "SELECT id, hostname from uaa_configs"
# update to hn
psql -d tempest_production -c "UPDATE uaa_configs set hostname='${HN}' where id=1"
# show the updated hostname
psql -d tempest_production -c "SELECT id, hostname from uaa_configs"
# A typical session
# ubuntu@ip-10-0-0-108:~$ sudo su -l postgres /home/ubuntu/hn.sh
# % Total % Received % Xferd Average Speed Time Time Time Current
# Dload Upload Total Spent Left Speed
# 100 40 100 40 0 0 3579 0 --:--:-- --:--:-- --:--:-- 4000
# id | hostname
# ----+------------------------------------------
# 1 | ec2-52-91-240-11.compute-1.amazonaws.com
# (1 row)
#
# UPDATE 1
# id | hostname
# ----+------------------------------------------
# 1 | ec2-52-90-243-58.compute-1.amazonaws.com
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment