Re: [Mongrel] Mongrel script and config options
If I can fix it and submit a patch... Add the gist link with the diff to the mongrel_service GitHub issue, I'll get that integrated ;-) I wish I knew anything about gist, but I made a simple change to mongrel_service-0.4.beta3\lib\mongrel_service\init.rb which I explained here: http://github.com/fauna/mongrel_service/issues/#issue/4 The modified file is enclosed. Cheers and thanks heaps Pete init.rb Description: Binary data ___ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users
Re: [Mongrel] Mongrel script and config options
On Tue, Apr 13, 2010 at 5:34 PM, Pete p...@kapiti.co.nz wrote: I need to pass some startup options on to my rails application. Using environment variables will not work because multiple mongrel clusters of my rails application (each of a slightly different flavour) served from a single code base can run concurrently and each cluster instance is activated via mongrel_service. Extra arguments passed in to either mongrel_rails service::install or mongrel_rails cause errors. I think you've already reported this to me here: http://github.com/fauna/mongrel_service/issues#issue/4 And if wasn't you, pretty much is similar request. The only documentation on the --script option I could find related to unix so I gave up on that thought. Script takes any Ruby script and execute it before starting mongrel, and is honored by mongrel_service I also tried using the --config option, but I had the same problem there: as soon as I added an option to the YAML file that wasn't documented, mongrel complained with an error. mongrel_rails start --help: -C, --config PATHUse a config file -S, --script PATHLoad the given file as an extra config script -G, --generate PATH Generate a config file for use with -C mongrel_rails start -G foo.yml ** Writing config to C:/Users/Luis/projects/secret/foo.yml. ** Finished. Run mongrel_rails start -C C:/Users/Luis/projects/secret/foo.yml to use the config file. The last one is a real nuisance. It just doesn't make sense that my config file should be restricted to content mongrel understands. Wouldn't it be a better approach to parse that file and look/apply the options mongrel recognises and provide a public interface so that other interested clients can access the config file? Sorry, but is the configuration file *for* mongrel, nobody says to you that you should use it. The problem is that you're trying to use the same application, the same checkout of it and everything to run multiple instances that are different on configuration settings. Apologizes for this but that is wrong. Even sharing database.yml could lead to problems. Or are there other ways to achieve this without resorting to modifying mongrel and mongrel services startup code? Do checkouts of your application on different directories. Have per-location configuration settings like config/settings.yml that is not part of your application source code. Is kind of complicated expect the same application folder serve multiple versions of the same application. Perhaps if you would explain better what are those settings we can advise you on different approaches. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exupéry ___ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users
Re: [Mongrel] Mongrel script and config options
On Tue, Apr 13, 2010 at 7:25 PM, Pete p...@kapiti.co.nz wrote: Interesting is also this page http://guides.rails.info/configuring.html which states under 2.Running Code Before Rails: To run some code before Rails itself is loaded, simply put it above the call to require 'rails/all' in your application.rb. If I log boot strapping of rails, I get this different sequences: when using mongrel via script/server (notice boot.rb appears twice!!!): boot.rb environment.rb boot.rb application.rb when using mongrel via mongrel_rails: environment.rb boot.rb application.rb Note that while the latter option is the common way to start the application, the former option is what I must use to debug my rails application under Netbeans. I would avoid script/server as it loads mongrel incorrectly. So clearly, running code (that fetches custom specific command line options) before rails starts doesn't work well with either environment, let alone both. Can I know how are you doing it? I've even tried to place such code inside environment.rb which is clearly loaded before application.rb and still had no luck. Which part? the top? the bottom? Which version of rails? If you place the code in config/preinitializer.rb it will be loaded before environment.rb fully loads. So far, the only way that worked for me is to modify library code and this is something a dread. Please be more specific with the examples. Show us code so we can replicate and workout solutions. You can't supply command line options to mongrel_rails that are not supported, however, you can use either environment variables or other stuff. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exupéry ___ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users
Re: [Mongrel] Mongrel script and config options
Hi Luis, Thanks for your reply. You're right, it was me who ask the same question in github, but since it was more related to mongrel_service and my issue has to do with rails boot strapping it didn't seem the right place. First up, I'm still using Rails 2.2.2. I'm sorry, but I don't agree with you that a single code base for multiple different rails application is a bad idea, quite the opposite actually. If you're really interested in what we're doing, this thread explains it in more detail: http://railsforum.com/viewtopic.php?pid=74217. It shouldn't be too hard to see the many advantages of a single code base over multiple code bases for serving multiple clients similar applications. As I said, I played with the --script option but couldn't get it to work. Here is how I start mongrel from the command line for client FOO: mongrel_rails start -e production -p 3035 -l log/FOO/mongrel.log -S config/FOO/myapp_opts.rb -c x:/myapp But config/FOO/myapp_opts.rb is never loaded (I've also tried specifying the full path x:/myapp/config/FOO/myapp_opts.rb to no avail). If this worked, it would solve my problem. So what am I doing wrong? Pete -Original Message- From: mongrel-users-boun...@rubyforge.org [mailto:mongrel-users- boun...@rubyforge.org] On Behalf Of Luis Lavena Sent: Wednesday, 14 April 2010 10:35 a.m. To: mongrel-users@rubyforge.org Subject: Re: [Mongrel] Mongrel script and config options On Tue, Apr 13, 2010 at 7:25 PM, Pete p...@kapiti.co.nz wrote: Interesting is also this page http://guides.rails.info/configuring.html which states under 2.Running Code Before Rails: To run some code before Rails itself is loaded, simply put it above the call to require 'rails/all' in your application.rb. If I log boot strapping of rails, I get this different sequences: when using mongrel via script/server (notice boot.rb appears twice!!!): boot.rb environment.rb boot.rb application.rb when using mongrel via mongrel_rails: environment.rb boot.rb application.rb Note that while the latter option is the common way to start the application, the former option is what I must use to debug my rails application under Netbeans. I would avoid script/server as it loads mongrel incorrectly. So clearly, running code (that fetches custom specific command line options) before rails starts doesn't work well with either environment, let alone both. Can I know how are you doing it? I've even tried to place such code inside environment.rb which is clearly loaded before application.rb and still had no luck. Which part? the top? the bottom? Which version of rails? If you place the code in config/preinitializer.rb it will be loaded before environment.rb fully loads. So far, the only way that worked for me is to modify library code and this is something a dread. Please be more specific with the examples. Show us code so we can replicate and workout solutions. You can't supply command line options to mongrel_rails that are not supported, however, you can use either environment variables or other stuff. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exupéry ___ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users ___ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users
Re: [Mongrel] Mongrel script and config options
On Tue, Apr 13, 2010 at 8:39 PM, Pete p...@kapiti.co.nz wrote: Hi Luis, First up, I'm still using Rails 2.2.2. I'm sorry, but I don't agree with you that a single code base for multiple different rails application is a bad idea, quite the opposite actually. If you're really interested in what we're doing, this thread explains it in more detail: http://railsforum.com/viewtopic.php?pid=74217. You're preaching to the wrong choir. I was the one that originated the approach of Radiant to build applications, and make gems of Rails applications with custom settings, database and configuration files. It was called fossilize, but due the constant internal changes of Rails was hard to keep it up. Since now is based on Rack (Rails 3), it might be easy to resurrect the idea. It shouldn't be too hard to see the many advantages of a single code base over multiple code bases for serving multiple clients similar applications. Is not that is hard to see, is hard to wrap Rails around that concept Reading your post what you actually need is more in the lines of Radiant approach: * make your application a gem * use a single directory for each individual application, but still depend on the same gem * extend or change the application with extensions from vendor, that might be different from client A to client B As I said, I played with the --script option but couldn't get it to work. Here is how I start mongrel from the command line for client FOO: mongrel_rails start -e production -p 3035 -l log/FOO/mongrel.log -S config/FOO/myapp_opts.rb -c x:/myapp But config/FOO/myapp_opts.rb is never loaded (I've also tried specifying the full path x:/myapp/config/FOO/myapp_opts.rb to no avail). If this worked, it would solve my problem. So what am I doing wrong? According to this: http://github.com/fauna/mongrel/blob/master/bin/mongrel_rails#L122-125 And this: http://github.com/fauna/mongrel/blob/master/lib/mongrel/configurator.rb#L342-348 The purpose of the config script is internal of Mongrel, not to setup stuff globally for the application like Rails. ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... ** Rails loaded. ** Loading any Rails specific GemPlugins ** Loading config/init_mongrel.rb external config script Also, it happens after Rails initialization. I would suggest you try the following: 1) put your init script code inside config/preinitializer.rb It gets executed by boot before Rails::Initializer.run of environment.rb. example: type config\preinitializer.rb STDERR.puts ARGV.inspect 2) Use something like MYAPP_TARGET=foo in the command line: mongrel_rails start MYAPP_TARGET=foo Will get you something like this: ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... [MYAPP_TARGET =foo] [MYAPP_TARGET =foo] ** Rails loaded. ** Loading any Rails specific GemPlugins (dunno why appears twice, is like the file gets loaded instead of required) 3) Add the additional parameter to created mongrel_service manually (registry editing) At this time, there is no way to specify additional parameters. I would like to move the configuration from command line to the registry, so is more easy to manipulate. That helps somehow? Thank you for explaining in further detail your need, it helped me provide you a better alternative. Of course, there is still room for improvement, and patches are always welcomed ;-) -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exupéry ___ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users
Re: [Mongrel] Mongrel script and config options
Hi Luis, You're preaching to the wrong choir. I'm glad ;) 2) Use something like MYAPP_TARGET=foo in the command line: mongrel_rails start MYAPP_TARGET=foo Will get you something like this: ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... [MYAPP_TARGET =foo] [MYAPP_TARGET =foo] ** Rails loaded. ** Loading any Rails specific GemPlugins (dunno why appears twice, is like the file gets loaded instead of required) ** *** WOW!!! *** ** I had no idea that would work. What are these things called? They're not really options, are they? Just tried it out and not only can I trap these options easily using preinitialize.rb with mongrel_service as well as mongrel_rails, but it also works perfectly fine in script/server (sorry, I know you don't like this and I trust your judgement, but it is the only option I have when debugging under Netbeans). THIS SOLVES MY PROBLEM! I missed this feature completely or it is undocumented. Had I known that a couple of weeks back I could have spent a week at the beach and would still be further than I am now. 3) Add the additional parameter to created mongrel_service manually (registry editing) For me that isn't a big deal since we have an installer and can easily configure the mongrel services during installation by writing to the registry directly. Thank you for explaining in further detail your need, it helped me provide you a better alternative. Of course, there is still room for improvement, and patches are always welcomed ;-) NO THANK YOU FOR YOUR HELP! Now I've also noticed that mongrel_rails service::install doesn't complain at all if I specify such glyphs (like MYAPP_TARGET=foo). However, they are not added to the ImagePath. If you think this would be useful, I see if I can fix it and submit a patch? Many thanks again, its hugely appreciated. ___ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users
Re: [Mongrel] Mongrel script and config options
On Tue, Apr 13, 2010 at 10:49 PM, Pete p...@kapiti.co.nz wrote: 2) Use something like MYAPP_TARGET=foo in the command line: mongrel_rails start MYAPP_TARGET=foo Will get you something like this: ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment... [MYAPP_TARGET =foo] [MYAPP_TARGET =foo] ** Rails loaded. ** Loading any Rails specific GemPlugins (dunno why appears twice, is like the file gets loaded instead of required) ** *** WOW!!! *** ** I had no idea that would work. What are these things called? They're not really options, are they? They are coming from ARGV, are not parsed by OptionParse (used by mongrel), so are just ignored and left available in ARGV. Just tried it out and not only can I trap these options easily using preinitialize.rb with mongrel_service as well as mongrel_rails, but it also works perfectly fine in script/server (sorry, I know you don't like this and I trust your judgement, but it is the only option I have when debugging under Netbeans). Hehe, well, if works for you for debugging will not say anything :) THIS SOLVES MY PROBLEM! Glad to hear that. I missed this feature completely or it is undocumented. Had I known that a couple of weeks back I could have spent a week at the beach and would still be further than I am now. config/preinitializer.rb is a hidden feature that actually nobody knows of it. It started to be more noticeable with the appearance of Bundler. Apologizes for you spending your time doing this, the mailing list should have been more exposed :( Now I've also noticed that mongrel_rails service::install doesn't complain at all if I specify such glyphs (like MYAPP_TARGET=foo). However, they are not added to the ImagePath. If you think this would be useful, I see if I can fix it and submit a patch? These options are not carried over. A minor patch that takes the left overs of ARGV and append to the registry line could work. Add the gist link with the diff to the mongrel_service GitHub issue, I'll get that integrated ;-) Many thanks again, its hugely appreciated. You're welcome :) Regards, -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exupéry ___ Mongrel-users mailing list Mongrel-users@rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users