<!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> </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> </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 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> </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> </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> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>if
defined?(REQUIRE2LIB)<BR> threadno1 = Thread.new {<BR>
ARGV << "start" << "-n" << "20"<BR> version
= "> 0"<BR> if ARGV.size > 0 && ARGV[0][0]==95
&& ARGV[0][-1]==95<BR> if
Gem::Version.correct?(ARGV[0][1..-2])<BR>
version = ARGV[0][1..-2]
<BR>
ARGV.shift<BR>
end<BR> end</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>
require_gem 'mongrel', version<BR> load 'mongrel_rails'
<BR> }</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006> sleep
30.0<BR>else<BR> ARGV << "start" << "-n" <<
"20"<BR> version = "> 0"<BR> if ARGV.size
> 0 && ARGV[0][0]==95 &&
ARGV[0][-1]==95<BR> if
Gem::Version.correct?(ARGV[0][1..-2])<BR>
version = ARGV[0][1..-2]
<BR>
ARGV.shift<BR>
end<BR> end</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=750295106-10052006>
require_gem 'mongrel', version<BR> load 'mongrel_rails'
<BR>end</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </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> </DIV>
<DIV><FONT face=Arial size=2>if not
defined?(RUBYSCRIPT2EXE)<BR> log "Loading any Rails specific
GemPlugins"<BR> load_plugins<BR>end</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>and</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>if not
defined?(RUBYSCRIPT2EXE)<BR> GemPlugin::Manager.instance.load
"mongrel" => GemPlugin::INCLUDE, "rails" =>
GemPlugin::EXCLUDE<BR>end</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </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. <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> </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> </DIV></DIV></BODY></HTML>