Skip to content

RightScale & Drupal - How to Get Internal IP Address

1 min read

I’m working on a new project that has a Drupal site running in the cloud–specifically Amazon AWS with RightScale sitting on top to manage our servers and automated scaling scripts.

The advantage of RightScale is it allows us to manage our servers at a further abstracted layer than AWS itself – through the use of “RightScripts” we can script our way through the managing of low level resources.

Things started to get a bit hairy when our scripts needed to talk to Drupal, in particular, registering each new server as it comes online with our Drupal stack, thereby whitelisting its IP address as trustworthy.

I did some googling and couldn’t find a good, efficient way to automate this, except for a post with a handy command.

With a little bit of tweaking, I arrived at a working solution that was even easier than thought.

First step is to prepare your settings.php or similar configuration file that holds your $conf[] for Drupal. We use IP address for a number of internal variables, but below are two Drupal specific variables used in ip_address():

  'reverse_proxy' => true,
  'reverse_proxy_addresses' => array(
    // load balancer IPs
    '1.2.3.4', // elastic ip address from AWS
  ),

The above code lives in our custom file that holds our Drupal $conf[] settings. We have a RightScript that copies this files to the proper location and after the file is copied over, I added this command:

sed -i "/load balancer IPs/ a\'$(hostname -i)'," db.inc

What this basically does is opens up our db.inc file which holds our Drupal $conf[], it searches for that specific “@load balancer IPs@” string (see above code snippet for where it was defined), than it appends a new line, adding in the IP address of that machine. If you have multiple machines registering themselves, this works quite nicely, as they keep growing the list.

Hope this helps someone else from banging their head around for a few hours!

codeDrupal

Related Posts

Members Public

The Future of Automotive Mobility will be Powered by Open Source Software

Automotive companies are shifting from bending metal to bending bits. Soon they will be offering software and services to complement their manufactured metal. In order to win in the market, they will need to embrace open-source software to build leverage and enhance their offering.

Members Public

How to Host Your Static Website on Amazon S3: Step-by-Step Guide

1. Login to your Amazon AWS account 2. Create a new hosted zone for your domain using Route 53 3. Copy the NS records for this zone to your domain provider (e.g., GoDaddy) 4. Edit your domain on your domain registrar (e.g., GoDaddy) by clicking Set Nameservers 5.

Members Public

Book Review: Drupal 7 Module Development

Well, it’s been a while my Drupal friends, almost 18 months… dusting off this old Drupal 6 blog and time to start posting again. And what better way to get started again than by talking about Drupal 7, by far the best release of Drupal. And with almost 7