# Dynamically add/remove mongrel on EC2 from Apache balancer

**URL:** <https://www.ruby-forum.com/t/dynamically-add-remove-mongrel-on-ec2-from-apache-balancer/129491>\
**Category:** Deployment\
**Created:** [February 19, 2008, 1:41am UTC](https://www.ruby-forum.com/t/dynamically-add-remove-mongrel-on-ec2-from-apache-balancer/129491 "2008-02-19T01:41:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [February 19, 2008, 1:41am UTC](https://www.ruby-forum.com/t/dynamically-add-remove-mongrel-on-ec2-from-apache-balancer/129491/1 "2008-02-19T01:41:04Z")

</div>

Hi,

I’d like to scale out by adding more EC2 mongrel instances, and scale  
down by removing EC2 mongrel instances.

Is there a way to dynamically add/remove mongrel instances from Apache  
mod\_proxy\_balancer. It seems that I’d have to manually change the  
configuration file and restart apache whenever I add/remove a new  
mongrel.

Yaxm

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [February 19, 2008, 11:06am UTC](https://www.ruby-forum.com/t/dynamically-add-remove-mongrel-on-ec2-from-apache-balancer/129491/2 "2008-02-19T11:06:21Z")

</div>

> Is there a way to dynamically add/remove mongrel instances from Apache  
> mod\_proxy\_balancer. It seems that I’d have to manually change the  
> configuration file and restart apache whenever I add/remove a new  
> mongrel.

Well, you could write a script to edit the config for you and send  
apache a usr1 signal ( “kill -usr1 [pid]” ) to cause it to reload the  
updated config, then trigger the script whenever a new EC2 instance is  
started or stopped.

Another approach could be to proxy everything to swiftiply (  
[http://swiftiply.swiftcore.org/](http://swiftiply.swiftcore.org/) ), and have each new EC2 instances  
mongrels register/deregister with the swiftiply proxy.

Yet another option would be to use switchpipe ( [http://switchpipe.org/](http://switchpipe.org/)  
) to manage things.

I haven’t done any of these, of course, so I’m basically talking  
through my hat, but they all sound plausible!

Good luck

David

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [February 19, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/dynamically-add-remove-mongrel-on-ec2-from-apache-balancer/129491/3 "2008-02-19T16:01:37Z")

</div>

On Tue, 2008-02-19 at 01:41 +0100, Yaxm Y. wrote:

> Is there a way to dynamically add/remove mongrel instances from Apache  
> mod\_proxy\_balancer. It seems that I’d have to manually change the  
> configuration file and restart apache whenever I add/remove a new  
> mongrel.

mod\_proxy\_balancer comes with the “balancer manager” with which can  
toggle a member of the cluster offline and back online:

[http://httpd.apache.org/docs/2.2/mod/mod\_proxy\_balancer.html](http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html)

You could script that interface and then call it from Capistrano. I  
Googled around but couldn’t find an existing library for this… kind of  
surprising. Maybe most folks are just going the “rewriting the config  
file and send USR1” route.

Yours,

Tom

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [February 22, 2008, 7:52pm UTC](https://www.ruby-forum.com/t/dynamically-add-remove-mongrel-on-ec2-from-apache-balancer/129491/4 "2008-02-22T19:52:00Z")

</div>

On Feb 19, 10:05 am, digitalronin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Is there a way to dynamically add/remove mongrel instances from Apache  
> > mod\_proxy\_balancer. It seems that I’d have to manually change the  
> > configuration file and restart apache whenever I add/remove a new  
> > mongrel.
> 
> [snip]
> 
> Yet another option would be to use switchpipe ([http://switchpipe.org/](http://switchpipe.org/)  
> ) to manage things.

Yep, that’s exactly what SwitchPipe does. Dynamically launches,  
manages, and kills backend processes that speak HTTP. Even better than  
that, it’ll kill Mongrels that aren’t in use for a certain period of  
time… so rather than having, say, 3 Mongrels running ALL the time on  
a quiet app, it’ll scale it back to zero Mongrels after X seconds of  
inactivity if you like. Alternatively you can make it keep 1 Mongrel  
up to pick up requests before scaling up to meet demand. Whatever you  
want to do, it does it.

Cheers,  
Peter C.  
[http://www.petercooper.co.uk/](http://www.petercooper.co.uk/)

---

<div class="post-metadata">

**Author:** ![yaxm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/54ee81/32.png) [@yaxm](https://www.ruby-forum.com/u/yaxm)\
**Post date:** [March 4, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/dynamically-add-remove-mongrel-on-ec2-from-apache-balancer/129491/5 "2008-03-04T17:57:03Z")

</div>

While dorking around, I found you can disable/enable mongrel instances  
in apache via curl. I added these two functions to my mongrel init  
file:

enable\_mongrel ()  
{  
curl -s -o /dev/null  
[http://127.0.0.1:8888/balancer-manager\?b=mongrel\_cluster\&w=http://127.0.0.1:$1\&dw\=ENABLE](http://127.0.0.1:8888/balancer-manager%5C?b=mongrel_cluster%5C&w=http://127.0.0.1:$1%5C&dw%5C=ENABLE)  
}

disable\_mongrel ()  
{  
curl -s -o /dev/null  
[http://127.0.0.1:8888/balancer-manager\?b=mongrel\_cluster\&w=http://127.0.0.1:$1\&dw\=DISABLE](http://127.0.0.1:8888/balancer-manager%5C?b=mongrel_cluster%5C&w=http://127.0.0.1:$1%5C&dw%5C=DISABLE)  
}

in the case statement:

```
enable)
  enable_mongrel $2
  RETVAL=$?

```

;;  
disable)  
disable\_mongrel $2  
RETVAL=$?  
;;

They accept the port number as an option. I use this as part of my  
monit system to keep things in check. I have a very high traffic site  
and I found proxy\_balancer didn’t react quick enough.

usage:

service monit disable 8081  
service monit enable 8081
