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:

  :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:		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

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

  • 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.

  • 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

  • Have you considered Sunspot for interacting with solr?

    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.

  • 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?

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

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