Maximilian Schoefmann
2006-Aug-03 19:00 UTC
[Mongrel] Finding out on which port mongrel is running
Hi *, What''s the best way to find out on which port mongrel is running from within Rails? I have a cluster of mongrels behind a balancer (Pen) behind a webserver (Apache). In Rails, request.port return 80 and request.env[''SERVER_PORT''] returns 3000 (the port of Pen) Any ideas? Cheers, Max
On 03/08/06, Maximilian Schoefmann <schoefma at cip.ifi.lmu.de> wrote:> What''s the best way to find out on which port mongrel is running from > within Rails?Why would you want to do this? If you set it up, you should know which ports you''ve configured... -- Dave Murphy (Schwuk) http://schwuk.com
Maximilian Schoefmann
2006-Aug-04 08:42 UTC
[Mongrel] Finding out on which port mongrel is running
> On 03/08/06, Maximilian Schoefmann <schoefma at cip.ifi.lmu.de> wrote: >> What''s the best way to find out on which port mongrel is running from >> within Rails? > > Why would you want to do this? If you set it up, you should know which > ports you''ve configured...I want to invoke a maintenance method on all instances through a webinterface. To do this I do a local http call to the other mongrels from the current mongrel. The problem is of course, that the current mongrel gets a timeout when it tries to call itself (thus I need to know the port to be able to skip it). I''m of course open for better ideas how to accomplish this Regards, Max
On Fri, Aug 04, 2006 at 10:42:26AM +0200, Maximilian Schoefmann wrote:> > On 03/08/06, Maximilian Schoefmann <schoefma at cip.ifi.lmu.de> wrote: > >> What''s the best way to find out on which port mongrel is running from > >> within Rails? > > > > Why would you want to do this? If you set it up, you should know which > > ports you''ve configured... > > I want to invoke a maintenance method on all instances through a > webinterface. To do this I do a local http call to the other mongrels from > the current mongrel. > The problem is of course, that the current mongrel gets a timeout when it > tries to call itself (thus I need to know the port to be able to skip it). > > I''m of course open for better ideas how to accomplish thisMaybe storing the port in an environment variable in the call to mongrel_rails would work ? something like: MONGREL_PORT=9200 mongrel_rails start -p $MONGREL_PORT -e production \ -a 127.0.0.1 -c /yourapp I think you could then access this via ENV[''MONGREL_PORT''] Jens -- webit! Gesellschaft f?r neue Medien mbH www.webit.de Dipl.-Wirtschaftsingenieur Jens Kr?mer kraemer at webit.de Schnorrstra?e 76 Tel +49 351 46766 0 D-01069 Dresden Fax +49 351 46766 66
Maximilian Schoefmann
2006-Aug-04 09:48 UTC
[Mongrel] Finding out on which port mongrel is running
> On Fri, Aug 04, 2006 at 10:42:26AM +0200, Maximilian Schoefmann wrote: >> > On 03/08/06, Maximilian Schoefmann <schoefma at cip.ifi.lmu.de> wrote: >> >> What''s the best way to find out on which port mongrel is running from >> >> within Rails? >> > >> > Why would you want to do this? If you set it up, you should know which >> > ports you''ve configured... >> >> I want to invoke a maintenance method on all instances through a >> webinterface. To do this I do a local http call to the other mongrels >> from >> the current mongrel. >> The problem is of course, that the current mongrel gets a timeout when >> it >> tries to call itself (thus I need to know the port to be able to skip >> it). >> >> I''m of course open for better ideas how to accomplish this > > Maybe storing the port in an environment variable in the call to > mongrel_rails would work ?Yes, this would be an option. Unfortunately I would loose the possibility to use the nice mongrel_cluster gem to manage my cluster (maybe this would be a useful addition to mongrel_cluster). I just thought that it should be possibile to find it out without using such tricks, as mongrel _has_ to know the port it is running on. But I couldn''t find something in the API docs of mongrel either.
Bradley Taylor
2006-Aug-04 12:26 UTC
[Mongrel] Finding out on which port mongrel is running
Hi:> Yes, this would be an option. Unfortunately I would loose the > possibility > to use the nice mongrel_cluster gem to manage my cluster (maybe > this would > be a useful addition to mongrel_cluster).The port is included in the name of the pid file. Could you just parse it from the file name? Regards, Bradley Taylor ------ Rails Optimized Hosting ~ VPS and Dedicated Servers Simplified Deployment ~ Services and Software http://railsmachine.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060804/e19dda4d/attachment.html
Maximilian Schoefmann
2006-Aug-04 13:01 UTC
[Mongrel] Finding out on which port mongrel is running
Hi,>> Yes, this would be an option. Unfortunately I would loose the >> possibility >> to use the nice mongrel_cluster gem to manage my cluster (maybe >> this would >> be a useful addition to mongrel_cluster). > > The port is included in the name of the pid file. Could you just > parse it from the file name?yes, that''s what I''m in fact doing now :-) But I have to open every file matching the mongrel.<portnumber>.pid pattern and check if the stored pid matches the current pid. ... not the most elegant solution :-/ but it works Cheers, Max
Philip Hallstrom
2006-Aug-04 16:33 UTC
[Mongrel] Finding out on which port mongrel is running
>>> Yes, this would be an option. Unfortunately I would loose the >>> possibility >>> to use the nice mongrel_cluster gem to manage my cluster (maybe >>> this would >>> be a useful addition to mongrel_cluster). >> >> The port is included in the name of the pid file. Could you just >> parse it from the file name? > > yes, that''s what I''m in fact doing now :-) > But I have to open every file matching the mongrel.<portnumber>.pid > pattern and check if the stored pid matches the current pid. > ... not the most elegant solution :-/ but it worksWe have the exception_notification plugin which emails us when there is a rails error... in that email we get the following: * URL: http://127.0.0.1:8004/search/results I just checked a couple of them and that :8004 changes to whatever the port is that is that mongrel. Digging through the code for the plugin I see this in a view: * URL: <%= @request.protocol %><%= @host %><%= @request.request_uri %> and this in a lib: :exception => exception, :host => request.env["HTTP_HOST"], We''re using apache 2.2 and mongrel 0.3.13.... So it''s gettable...
On Thu, 2006-08-03 at 21:00 +0200, Maximilian Schoefmann wrote:> Hi *, > > What''s the best way to find out on which port mongrel is running from > within Rails? > I have a cluster of mongrels behind a balancer (Pen) behind a webserver > (Apache). > > In Rails, > request.port return 80 > and > request.env[''SERVER_PORT''] returns 3000 (the port of Pen) > > Any ideas?First off, doing this "connect back to mongrel" in rails is bad news. It''ll lock up on you because Rails is locked while your making the request so you deadlock. Second, you should be doing this with an external monitor like monit. I highly recommend monit. And since you''re using mongrel_cluster you should know what ports they''re configured on. But, you''ll probably want to continue with your idea anyway, so go check out handlers.rb StatsHandler and see how it''s printing out stats. Every handler has access to it''s "listener". So the snippet: results << table("settings", [ ["host",listener.host], ["port",listener.port], ["timeout",listener.timeout], ["workers max",listener.num_processors], ]) Is printing the host, port, and other setting for the handlers listener. So, write a mongrel handler and you won''t have to worry about rails locking. The RDoc has more info like this. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?
Maximilian Schoefmann
2006-Aug-07 07:32 UTC
[Mongrel] Finding out on which port mongrel is running
>>>> Yes, this would be an option. Unfortunately I would loose the >>>> possibility >>>> to use the nice mongrel_cluster gem to manage my cluster (maybe >>>> this would >>>> be a useful addition to mongrel_cluster). >>> >>> The port is included in the name of the pid file. Could you just >>> parse it from the file name? >> >> yes, that''s what I''m in fact doing now :-) >> But I have to open every file matching the mongrel.<portnumber>.pid >> pattern and check if the stored pid matches the current pid. >> ... not the most elegant solution :-/ but it works > > We have the exception_notification plugin which emails us when there is a > rails error... in that email we get the following: > > * URL: http://127.0.0.1:8004/search/results > > I just checked a couple of them and that :8004 changes to whatever the > port is that is that mongrel. Digging through the code for the plugin I > see this in a view: > > * URL: <%= @request.protocol %><%= @host %><%= @request.request_uri %> > > and this in a lib: > > :exception => exception, :host => request.env["HTTP_HOST"], > > We''re using apache 2.2 and mongrel 0.3.13.... > > So it''s gettable...I''m sure Apache 2.2/mod_proxy_balancer does a better job in forwarding the correct port to rails. Unfortunately I''m doomed to Apache 2.0 / Pen here. But good to know.