Run 'Change IP Addresses' automatically on boot for amazon ec2 hosts

9 posts / 0 new
Last post
#1 Mon, 09/24/2012 - 07:13
mnt_schred

Run 'Change IP Addresses' automatically on boot for amazon ec2 hosts

I've seen the same question some times now on this forum, but I'll ask it again to see if there are new developments.

I have a very large amazon instance for heavy traffic for one of my websites. On boot the machine syncs the website and database and places itselfs in the Amazon ELB (loadbalancer), and disables the machine forwarding all the traffic to my static virtualmin machine.

This works perfectly, except for the fact that the IP address given to the machine changes everytime and Virtualmin only works with the previous, static IP.

The solution would off course be to run the Change IP Addresses script on boot automatically. Is this possible?

Mon, 09/24/2012 - 13:18
andreychek

Howdy,

Beginning in Virtualmin 3.94, if Virtualmin detects a changed IP address, it should prompt you to update the IP's that it's configured to use.

It would only prompt the Master Admin user.

I don't know if there's a way to do that from the command line though... I can ask Jamie about that.

-Eric

Tue, 09/25/2012 - 14:32
andreychek

While logging into Virtualmin and handling it there is the simplest way to update the IP, that's not automated... Jamie suggested the following code as an automated way of updating the IP:

newip=`hostname -i`
for dom in `virtualmin list-domains --name-only`; do
  virtualmin modify-domain --domain $dom --shared-ip $newip
done

You'd want to test all that though -- in particular, you'd want to make sure that "hostname -i" returns your correct Ip address.

-Eric

Tue, 09/25/2012 - 16:49 (Reply to #3)
mnt_schred

And where should this be executed? Not simply from shell..

Tue, 09/25/2012 - 18:37
andreychek

Howdy,

After verifying that the above code does what you want (we haven't tested it on an EC2 system), you could put it in a shell script, and have that shell script run automatically when your system boots up.

-Eroc

Fri, 09/28/2012 - 12:56
mnt_schred

Well, the 'virtualmin' command is not found in shell.. does this also apply for virtualmin GPL?

Fri, 09/28/2012 - 13:05
andreychek

Yup, that should be available on both Virtualmin Pro and Virtualmin GPL.

It's possible that it's just not in your path... rather than "virtualmin", try running "/usr/sbin/virtualmin".

-Eric

Tue, 10/02/2012 - 06:04
mnt_schred

awesome. Today I solved a problem BUT also learned the fantastic fact that a whole script enviroment exists for virtualmin!

I cannot fathom, after using webmin/virtualmin for almost 7 years what a great product it is..

this is the final script btw:

#!/bin/bash
newip=`hostname -i`
for dom in `/usr/sbin/virtualmin list-domains --name-only`; do
  /usr/sbin/virtualmin modify-domain --domain $dom --shared-ip $newip
done

runs at boot (cron) and I'm all happy :)

Tue, 10/02/2012 - 09:22
andreychek

Super, I'm glad you got that working, thanks for sharing your final script with us!

Topic locked