On my local machine, i run rails with mongrel. I have some stuff which runs when it starts, via a file in config/initializers, which uses puts to tell me which database it's using, what is being used to send emails, and a few other bits of info.
When I run a cluster of mongrels, on ports 3000, 3001 and 3002, I only want to do this reporting stuff for the mongrel on port 3000. So, I need to wrap it in an if block which tests which port the currently running mongrel is using. Can anyone tell me how I can get this in my code?
Ok, i'm answering my own question as i just figured it out after setting a bounty!
I can get the pid of the currently running process with
Process.pid. Then i can dops afx | grep mongrelwhich gives me a result like thiswhich i can then grep for the pid, and read the port number out of the matching line, and see if it's 3000.
So, my code is
BTW, if someone can tell me how to directly get the port of the running mongrel, without going via
ps afxandProcess.pidi'll still give you the bounty :)