VM post startup script and heart beat

In last post, I created vagrant base box and use it to start VM to run Ubuntu 12.04 server.
Now I want to hook the VMs with the internal DNS servers, which means
1, VMs should be able to “report” its IP address (I am using DHCP)
2, DNS server should be able to receive VM message and update its bind9 files
3, VM needs to update its ResolvConf head file to have the internal DNS

At VM side, I think it can run a post-startup script to find and report its IP

I found this command will display the host IP (eth0) and VM ip (eth1)
/sbin/ifconfig | grep “inet addr” | grep -v “” | awk ‘{ print $2 }’ | awk -F: ‘{ print $2 }’

1, sudo apt-get install curl
2, vi ~/post_startup.sh
echo after vm started …
/sbin/ifconfig | grep “inet addr” | grep -v “” | awk ‘{ print $2 }’ | awk -F: ‘{ print $2 }’ > my.ip
echo done of post-start-up
curl -X POST –data-binary @my.ip http://my-host-address/service/box-is-up
chmod +x post_startup.sh

add to local-rc
sudo cp post_startup.sh /etc/init.d
sudo chmod +x /etc/init.d/post_startup.sh
sudo update-rc.d post_startup.sh defaults 98 02

at the server side, the web app needs to parse the passed body and update the DNS records in two files
db.xx.yy (reverse ip)

may add a crontab job to broadcast the my.op periodically as a heartbeat from VM
*/2 * * * * ~/broadcast.sh > /dev/null 2>&1

Also, install Oracle JDK 1.7 and Git on the VM. We can install Java through Chef, but this is much easier by installing on a vagrant VM and create a base box from it or create a custom EC2 image.
Now we are at it, install git too.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s