Mark Needham

Thoughts on Software Development

Local port forwarding

with 5 comments

A colleague and I ran into an interesting problem today which we wanted to use local port forwarding to solve.

In our environment.rb file we have a Solr instance url defined like so:

SOLR_CONFIG = {
  :service_url => "http://some.internal.address:9983/solr/sco_slave_1"        
}

It’s defined like that because our colleagues in Chicago have setup a Solr instance on a test environment and all the developers hit the same box.

In Pune everyone has Solr configured on their own box so we really wanted to configure that url to be ‘localhost’ on port ’8983′.

Several other colleagues have just changed their environment.rb file and then remember not to check that in.

I always forget about that type of thing though so I wanted to find a work around.

We started by putting the following in /etc/hosts:

127.0.0.1		some.internal.address

Having done that we needed to forward anything coming in on port 9983 to 8983 to complete the forwarding.

I think there’s a proper way of doing this using iptables but we didn’t want to shave the yak and hence used this tcpforward perl script:

./tcpforward -k -l some.internal.address:9983 -c 127.0.0.1:8983

If anyone knows a better way or the proper way to do this I’d be interesting in hearing about that but for now this does the job!

Be Sociable, Share!

Written by Mark Needham

November 29th, 2010 at 7:42 pm

  • http://www.franzoni.eu Alan Franzoni

    I’m not really a Ruby guy, but the “proper” way to do it would be to read additional, per-user config from some place in the user’s home directory, and override the app’s configuration with any value it’s found there.

    Anyone could then just configure whatever service_url is appropriate for their context.

  • http://www.markhneedham.com Mark Needham

    I figured that might be the proper way but I wasn’t sure of the exact convention for where you should place the file, how it would get called etc

  • http://www.wikyblog.com/AmanKing Aman King

    Have you considered Sunspot for interacting with solr?
    http://outoftime.github.com/sunspot/

    For Rails, sunspot supports reading a config/sunspot.yml (similar to what Rails does with config/database.yml). You could keep a sunspot.yml.sample version controlled and have folks copy it over locally as sunspot.yml and modify the latter if needed (sunspot.yml would have to be ignored for version control). You could have a rake/capistrano task for automating the copying, etc.

  • http://www.markhneedham.com Mark Needham

    We’re using RSolr-ext at the moment. I don’t know much about the differences between that and solr but the guys said it’s better for doing faceted searching?

  • http://thinkaround.blogspot.com Saager Mhatre

    Dude, why do you need tcpforward for local port forwarding on OSX? Just use SSH!

    ssh -L 8983:some.internal.address:9983 you@localhost