views:

116

answers:

3

Dear all,

Stupid question - apologies in advance.

I have a mixed Windows and Linux dev environment, and the server is Linux (Ubuntu). Let's say the server is called 'myserver'.

I develop on both Windows and *nix (Ubuntu and OS X), with references to myserver as 'myserver.local' on *nix, and 'myserver' on Windows.

I have shared code references (e.g. MySQL connection strings, HTTP remoting references etc) which I have to change depending on which dev env I'm in, which is nuts. For the life of me I can't work out how to force Windows to alias 'myserver.local' to 'myserver' and make the world a better place.

Any ideas?

Many thanks, Ned

+1  A: 

somewhere in /system32 is a file called hosts where you can enter host names to your heart's content, those names will be respected by the resolver. Should fix your problem.

Carl Smotricz
I thought hosts was just for ip aliases?Let me go try...Thanks buddy!
Ned Lowe
It is - but that thing near the beginning of a MySQL URL is just that. How do you think MySQL communicates? ;)
Carl Smotricz
That's not what I meant... I mean - I'm using dynamic ip on all my boxes, so all my various services (MySQL, a couple of Tomcat instances, blah blah) can be accessed as 'http:\\myservername.local:8080' etc). But when it's Windows consuming the service (or MySQL or whatever) I need to mess with my code to 'http:\\myservername:8080'.If I can make a hosts entry that says:127.0.0.1 localhostmyservername myservername.localThen all good, but I didn't think you could. I just tried and it didn't work, but I might have done something dumb so I'm just checking...Thanks for helping though.
Ned Lowe
OK the formatting on that was not what I intended. Mentally imagine a CRLF after localhost :-)
Ned Lowe
That might be the problem - all the aliases for your IP address go on the same line. Just string together as many as you like!
Carl Smotricz
Oohh no, I misunderstood you. You can alias all that stuff to localhost, but that won't help you assign another name to a symbolic address. Sorry about that! And back to the drawing board...
Carl Smotricz
Those are two totally different references - sorry, ignore the localhost line, I was just putting it in for context. The aliasing I need is very much not to localhost, or there wouldn't be a problem :-)
Ned Lowe
You got it... Hmmm... Surely this is a standard issue for people with eclectic tastes in operating systems... OK, Google - I hope you're my friend...
Ned Lowe
A: 

Windows has a hosts file you can change to make myserver.local resolve to 127.0.0.1, just the same as Linux. It's just hidden in Windows\System32\drivers\etc\HOSTS. But if you always want to use the local server for your references, why not simply write localhost?

In general though you should aim to keep your deployment settings apart from your application rather than sharing them. It would depend on what language/platform you're talking about of course, but in my case using Python I use a script to invoke the application something like:

hostname= socket.gethostname()

if hostname=='devbox':
   def dbfactory():
       return MySQLdb.connect(db= 'myapp', user= 'foo', passwd= 'bar')
   myapp= mymodule.Application(dbfactory, debug= True)

elif hostname=='www':
   def dbfactory():
       return MySQLdb.connect(db= 'myapplive', unix_socket= '/usr/local/var/mysql/socket', user= 'baz')
   myapp= mymodule.Application(dbfactory, debug= False)

else:
    raise NotImplementedError('No known deployment config for machine %r' % hostname)

myapp.run()
bobince
Thanks for replying - but please see comments above.This isn't for localhost. I have a few servers dotted about that run various services for me. This is consuming code.And yes - my config is totally separate, which is why it hasn't been impossible to manage (I checkout my config files on Windows when an update is made and just remove all the '.local' strings from my references, then don't check them in again).
Ned Lowe
Yeah, I'm suggesting having both the dev and production config checked in, and having the app decide which to use by sniffing for which machine it's on.
bobince
This is the exact same dev config. It's just due to the annoying difference between the way Windows and Linux resolve servernames within a network. Windows wants the format as http:\\servername:port and *nix wants http:\\servername.local:port. So I was thinking of aliasing in the '.local' bit for Windows.
Ned Lowe
I suppose I should clarify that slightly - it's my use of Zeroconf/mDNS/Avahi which uses the .local - not Linux in general.
Ned Lowe
A: 

Alternate answer:

I once had similar problems and got tired of having to reconfigure my app all the time. My solution there was similar to what bonince is suggesting:

The idea is to have your app configure itself differently depending on where it is. I wouldn't recommend "sniffing," though. I'd prefer something more "official" and "specific." To wit, there should be some data found in the same place on both machines but with different contents. Two possibilities come to mind:

  • Environment variables. They're deprecated in Java, but they work fine under Linux and Windows. If you have access to to the startup scripts, you can set whatever you like, and query the values from Java.

  • Properties/configuration files outside the project itself. I used a directory called /local (linux) and C:\Local (Windows) to contain bits and pieces of configuration that I wanted to be host specific. The home directory also works fine for this kind of thing; every host has one, and Java generally knows how/where to find it.

Carl Smotricz