<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN class=843102010-26052006>Hi 
All</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=843102010-26052006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=843102010-26052006>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.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=843102010-26052006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=843102010-26052006>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 (<A 
title=http://www.erikveen.dds.nl/distributingrubyapplications/rails.html 
href="http://www.erikveen.dds.nl/distributingrubyapplications/rails.html">http://www.erikveen.dds.nl/distributingrubyapplications/rails.html</A>) 
provides a mechanism to generate a minimal size download with everything needed 
to run the&nbsp;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)!</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=843102010-26052006></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT><SPAN class=843102010-26052006>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>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.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>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:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>if 
defined?(REQUIRE2LIB)<BR>&nbsp; threadno1 = Thread.new {<BR>&nbsp;&nbsp;&nbsp; 
ARGV &lt;&lt; "start" &lt;&lt; "-n" &lt;&lt; "20"<BR>&nbsp;&nbsp;&nbsp; version 
= "&gt; 0"<BR>&nbsp;&nbsp;&nbsp; if ARGV.size &gt; 0 &amp;&amp; ARGV[0][0]==95 
&amp;&amp; ARGV[0][-1]==95<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
Gem::Version.correct?(ARGV[0][1..-2])<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
version = ARGV[0][1..-2] 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
ARGV.shift<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
end<BR>&nbsp;&nbsp;&nbsp; end</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>&nbsp;&nbsp;&nbsp; 
require_gem 'mongrel', version<BR>&nbsp;&nbsp;&nbsp; load 'mongrel_rails'&nbsp; 
<BR>&nbsp; }</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>&nbsp; sleep 
30.0<BR>else<BR>&nbsp;&nbsp;&nbsp; ARGV &lt;&lt; "start" &lt;&lt; "-n" &lt;&lt; 
"20"<BR>&nbsp;&nbsp;&nbsp; version = "&gt; 0"<BR>&nbsp;&nbsp;&nbsp; if ARGV.size 
&gt; 0 &amp;&amp; ARGV[0][0]==95 &amp;&amp; 
ARGV[0][-1]==95<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
Gem::Version.correct?(ARGV[0][1..-2])<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
version = ARGV[0][1..-2] 
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
ARGV.shift<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
end<BR>&nbsp;&nbsp;&nbsp; end</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>&nbsp;&nbsp;&nbsp; 
require_gem 'mongrel', version<BR>&nbsp;&nbsp;&nbsp; load 'mongrel_rails'&nbsp; 
<BR>end</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV><SPAN class=750295106-10052006>
<DIV><BR><FONT face=Arial size=2>2. Although this mechanism generates the 
package, when we come to run the executable, the gem_plugin mechanism fails<SPAN 
class=843102010-26052006>.</SPAN> 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:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if not 
defined?(RUBYSCRIPT2EXE)<BR>&nbsp;&nbsp;&nbsp; log "Loading any Rails specific 
GemPlugins"<BR>&nbsp;&nbsp;&nbsp; load_plugins<BR>end</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>and</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>if not 
defined?(RUBYSCRIPT2EXE)<BR>&nbsp;&nbsp;&nbsp; GemPlugin::Manager.instance.load 
"mongrel" =&gt; GemPlugin::INCLUDE, "rails" =&gt; 
GemPlugin::EXCLUDE<BR>end</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT 
face=Arial size=2></FONT><FONT face=Arial size=2></FONT><BR><FONT 
face=Arial><FONT size=2>With these two changes, the packaged exe can now 
successfully run mongrel with our rails application.&nbsp;<SPAN 
class=843102010-26052006>Can anybody see a reason why this is a bad thing to do 
or have suggestions on how this can be improved.</SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2><SPAN 
class=843102010-26052006>---</SPAN></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2>Jon<SPAN class=843102010-26052006> 
Fernyhough</SPAN><BR><SPAN class=843102010-26052006><A 
href="http://www.zogix.com">http://www.zogix.com</A></SPAN></FONT></FONT></DIV>
<DIV><FONT face=Arial><FONT size=2><SPAN 
class=843102010-26052006></SPAN></FONT></FONT></SPAN></SPAN></FONT><FONT 
face=Arial size=2><STRONG></STRONG></FONT>&nbsp;</DIV></DIV></BODY></HTML>