Hi All First of all - I would like to say Mongrel is fantastic! We are developing a hybrid solution incorporating a central server and local servers (which allows offline working) - with Webrick we were suffering from 500 (and other errors) that the switch to Mongrel has fixed. Since we are providing the local server as a download application we wanted to find a way to package up the code and ruby modules that were being used. Erik Veenstra packaging application (http://www.erikveen.dds.nl/distributingrubyapplications/rails.html) provides a mechanism to generate a minimal size download with everything needed to run the ruby application. We had to overcome a couple of issues to get the package working with Mongrel and thought it good to share that info (and check that we haven''t done something stupid)! 1. The first problem we had to overcome is in generating the exe package using Erik''s rubyscript2exe. In generating an executable you need to include an "init.rb" file that starts Mongrel. This file is also executed during the packaging to determine which libraries need to be included. With webrick, once the server starts you stop it using Ctrl-C, which shuts the server down and allows the packaging script to complete. Using Mongrel on windows, the only way to stop the server is Ctrl-Break - which also stops the packaging process itself. On Linux I''m sure we could have used the "mongrel_rails stop" command but did not have that luxury on Windows. Instead, we found that we could start the mongrel server in a thread, combined with an appropriate sleep period the init.rb process terminates without us having to stop the server and allows rubyscript2exe to gather all the appropriate libraries. This is not what we want when we actually run the packaged exe - so we set a condition in the init.rb file that uses the thread during packaging and starts the server normally when we run the packaged exe: if defined?(REQUIRE2LIB) threadno1 = Thread.new { ARGV << "start" << "-n" << "20" version = "> 0" if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95 if Gem::Version.correct?(ARGV[0][1..-2]) version = ARGV[0][1..-2] ARGV.shift end end require_gem ''mongrel'', version load ''mongrel_rails'' } sleep 30.0 else ARGV << "start" << "-n" << "20" version = "> 0" if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95 if Gem::Version.correct?(ARGV[0][1..-2]) version = ARGV[0][1..-2] ARGV.shift end end require_gem ''mongrel'', version load ''mongrel_rails'' end 2. Although this mechanism generates the package, when we come to run the executable, the gem_plugin mechanism fails. Since our download does not rely on any plugins we added a couple of conditions in the mongrel_rails file to disable the plugin mechanism: if not defined?(RUBYSCRIPT2EXE) log "Loading any Rails specific GemPlugins" load_plugins end and if not defined?(RUBYSCRIPT2EXE) GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE, "rails" => GemPlugin::EXCLUDE end With these two changes, the packaged exe can now successfully run mongrel with our rails application. Can anybody see a reason why this is a bad thing to do or have suggestions on how this can be improved. --- Jon Fernyhough http://www.zogix.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mongrel-users/attachments/20060526/af804bcc/attachment-0001.htm
On 5/26/06, Jon Fernyhough <jon.fernyhough at zogix.com> wrote:> > > Hi All > > First of all - I would like to say Mongrel is fantastic! We are developing a > hybrid solution incorporating a central server and local servers (which > allows offline working) - with Webrick we were suffering from 500 (and other > errors) that the switch to Mongrel has fixed. > > Since we are providing the local server as a download application we wanted > to find a way to package up the code and ruby modules that were being used. > Erik Veenstra packaging application > (http://www.erikveen.dds.nl/distributingrubyapplications/rails.html) > provides a mechanism to generate a minimal size download with everything > needed to run the ruby application. We had to overcome a couple of issues to > get the package working with Mongrel and thought it good to share that info > (and check that we haven''t done something stupid)! >The other thing you could use is All In One Ruby (also from Erik Veenstra) http://www.erikveen.dds.nl/allinoneruby/index.html> 1. The first problem we had to overcome is in generating the exe package > using Erik''s rubyscript2exe. In generating an executable you need to include > an "init.rb" file that starts Mongrel. This file is also executed during the > packaging to determine which libraries need to be included. With webrick, > once the server starts you stop it using Ctrl-C, which shuts the server down > and allows the packaging script to complete. Using Mongrel on windows, the > only way to stop the server is Ctrl-Break - which also stops the packaging > process itself.On the beta gem (0.3.13) that issue is solved, so you could use Cntrl-C without problem in Windows or Linux. [...]> > if defined?(REQUIRE2LIB) > threadno1 = Thread.new { > ARGV << "start" << "-n" << "20" > version = "> 0" > if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95 > if Gem::Version.correct?(ARGV[0][1..-2]) > version = ARGV[0][1..-2] > ARGV.shift > end > end > > require_gem ''mongrel'', version > load ''mongrel_rails'' > } > > sleep 30.0 > else > ARGV << "start" << "-n" << "20" > version = "> 0" > if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95 > if Gem::Version.correct?(ARGV[0][1..-2]) > version = ARGV[0][1..-2] > ARGV.shift > end > end > > require_gem ''mongrel'', version > load ''mongrel_rails'' > end >I would suggest you replace the big sleep with small intervals: 30.times do sleep 1 end That will wait 30 seconds, but tell ruby scheduler to allow running its other threads.> > 2. Although this mechanism generates the package, when we come to run the > executable, the gem_plugin mechanism fails. Since our download does not rely > on any plugins we added a couple of conditions in the mongrel_rails file to > disable the plugin mechanism:[...] I have seen similar issues with gem_plugin running it as services. I''ll suggest try the same env. using All In One Ruby which is more "traditional" than the script2exe.> > With these two changes, the packaged exe can now successfully run mongrel > with our rails application. Can anybody see a reason why this is a bad thing > to do or have suggestions on how this can be improved. >I have investigated the scenario you describe before, for the same purpose as you, but maintaining a packaged exe is more complicated than packaged zip with AIO Ruby. Also, we found that the late requiring done by the magic of rails often don''t load all the libraries needed by the package, and fails miserably (with sqlite3 and mysql we tested that). Just my comments and suggestions. Regards, -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi
On Fri, 2006-05-26 at 11:39 +0100, Jon Fernyhough wrote:> ? > Hi All ><snip>> Since we are providing the local server as a download application we > wanted to find a way to package up the code and ruby modules that were > being used. Erik Veenstra packaging application > (http://www.erikveen.dds.nl/distributingrubyapplications/rails.html) > provides a mechanism to generate a minimal size download with > everything needed to run the ruby application. We had to overcome a > couple of issues to get the package working with Mongrel and thought > it good to share that info (and check that we haven''t done something > stupid)!<snip>> > With these two changes, the packaged exe can now successfully run > mongrel with our rails application. Can anybody see a reason why this > is a bad thing to do or have suggestions on how this can be improved. >Hey Jon, that''s great. Do you think you''d like to write some documentation on this for the Mongrel site? Take a look at: http://mongrel.rubyforge.org/docs/contrib.html And then follow the instructions if you''re interested. I''m sure other folks would like it. Since it''s wiki syntax for the documentation (using webgen) you could probably start off by just cut-pasting your e-mail into a text file and cleaning it up a bit. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/
Hi Zed - we are currently finalising our beta release - but when I get chance will be happy to write some documentation for the Mongrel site. Jon Fernyhough Zogix Ltd -----Original Message----- From: mongrel-users-bounces at rubyforge.org [mailto:mongrel-users-bounces at rubyforge.org] On Behalf Of Zed Shaw Sent: 26 May 2006 18:40 To: mongrel-users at rubyforge.org Subject: Re: [Mongrel] Packaging with mongrel On Fri, 2006-05-26 at 11:39 +0100, Jon Fernyhough wrote:> ? > Hi All ><snip>> Since we are providing the local server as a download application we > wanted to find a way to package up the code and ruby modules that were > being used. Erik Veenstra packaging application > (http://www.erikveen.dds.nl/distributingrubyapplications/rails.html) > provides a mechanism to generate a minimal size download with > everything needed to run the ruby application. We had to overcome a > couple of issues to get the package working with Mongrel and thought > it good to share that info (and check that we haven''t done something > stupid)!<snip>> > With these two changes, the packaged exe can now successfully run > mongrel with our rails application. Can anybody see a reason why this > is a bad thing to do or have suggestions on how this can be improved. >Hey Jon, that''s great. Do you think you''d like to write some documentation on this for the Mongrel site? Take a look at: http://mongrel.rubyforge.org/docs/contrib.html And then follow the instructions if you''re interested. I''m sure other folks would like it. Since it''s wiki syntax for the documentation (using webgen) you could probably start off by just cut-pasting your e-mail into a text file and cleaning it up a bit. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ _______________________________________________ Mongrel-users mailing list Mongrel-users at rubyforge.org http://rubyforge.org/mailman/listinfo/mongrel-users