Discussion:
auto-reload issue
Dennis Sutch
2007-04-27 19:56:01 UTC
Permalink
I'm able to successfully use mod_ruby to serve a Ruby script. After I add
the "RubyRequire auto-reload" directive (and restart Apache), changes to my
script are not reflected when I reload my browser. Is there something else
that I need to do (see configuration below)? Does auto-reload work in the
current version of mod_ruby?

Here's what I'm using:

Red Hat Enterprise Linux 3
Apache 2.0.46
Ruby 1.8.5
mod_ruby 1.2.6

The important section from httpd.conf file:

<VirtualHost *:80>
SetHandler ruby-object
RubyTimeOut 30
RubyRequire auto-reload
RubyAddPath /var/www/myapp/bin
RubyRequire myapp
RubyHandler MyApp.instance
</VirtualHost>
--
Dennis Sutch
***@sutch.com
Shugo Maeda
2007-05-08 09:26:55 UTC
Permalink
Hi,
Post by Dennis Sutch
I'm able to successfully use mod_ruby to serve a Ruby script. After I
add the "RubyRequire auto-reload" directive (and restart Apache),
changes to my script are not reflected when I reload my browser. Is
there something else that I need to do (see configuration below)? Does
auto-reload work in the current version of mod_ruby?
auto-reload doesn't affect RubyRequire.
It only affects require in Ruby scripts.

For example, the following script reload foo.rb when foo.rb is modified.

test.rbx:
require "foo"
r = Apache.request
r.content_type = "text/plain"
...
Post by Dennis Sutch
<VirtualHost *:80>
SetHandler ruby-object
RubyTimeOut 30
RubyRequire auto-reload
RubyAddPath /var/www/myapp/bin
RubyRequire myapp
RubyHandler MyApp.instance
</VirtualHost>
You have to restart Apache to reload MyApp:(

Shugo
Dennis Sutch
2007-05-08 14:36:49 UTC
Permalink
Thanks for the response.

Is there something else that I need to do? (see below)
Post by Shugo Maeda
auto-reload doesn't affect RubyRequire.
It only affects require in Ruby scripts.
For example, the following script reload foo.rb when foo.rb is modified.
require "foo"
r = Apache.request
r.content_type = "text/plain"
...
Post by Dennis Sutch
<VirtualHost *:80>
SetHandler ruby-object
RubyTimeOut 30
RubyRequire auto-reload
RubyAddPath /var/www/myapp/bin
RubyRequire myapp
RubyHandler MyApp.instance
</VirtualHost>
I've created a myapp-loader.rb and required that with RubyRequire. The
myapp-loader requires myapp.

In other words: RubyRequire loads myapp-loader.rb, which in turn loads
myapp.rb, which then loads other Ruby scripts. Using this method, should
auto-reload notice changes to any script other than myapp-loader.rb?

Yet, when changes are made to myapp or any of the scripts required by myapp,
those changes do not show up until Apache is restarted. Is there something
else that I may need to do to make auto-reload work?
--
Dennis Sutch
***@sutch.com
Shugo Maeda
2007-05-09 02:44:20 UTC
Permalink
Hi,
Post by Dennis Sutch
Post by Dennis Sutch
<VirtualHost *:80>
SetHandler ruby-object
RubyTimeOut 30
RubyRequire auto-reload
RubyAddPath /var/www/myapp/bin
RubyRequire myapp
RubyHandler MyApp.instance
</VirtualHost>
I've created a myapp-loader.rb and required that with RubyRequire. The
myapp-loader requires myapp.
In other words: RubyRequire loads myapp-loader.rb, which in turn loads
myapp.rb, which then loads other Ruby scripts. Using this method,
should auto-reload notice changes to any script other than myapp-loader.rb?
auto-reload doesn't reload scripts in this situation.
Because top-level require in myapp-loader.rb is called only once.
auto-reload just replace buitin require, so if require isn't called,
nothing happens.

You should place require in the handler method in your MyApp to
reload scripts on each request.

Shugo

Loading...