Forums | Admin

Discussion Forums: open-discussion

Start New Thread Start New Thread

 

By: Vivek Pandey
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 23:07
Few tips about JVM config: JRuby needs more perm gen space (it depends on your app of course). Here are some of the settings you might consider running your app with these settings:

jruby -J-Xmx512m -J-XX:MaxPermSize=192m -J-XX:NewRatio=2 -J-XX:+DisableExplicitGC -J-Dhk2.file.directory.changeIntervalTimer=6000 -S glassfish

When you run glassfish in daemon mode (only on linux and solaris currently), it automatically runs with these options.

Also, I dont need to mention but you might already be running your application in production environment. Also a bit about running in multithreaded mode, if the gems you are running are thread-safe, it might be worth trying enabling thread-safe mode.

Please keep us updated. We would definitely like to move to production on GlassFish:)



By: Aaron Reichman
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 19:27
FYI, after I got this all working I started to discover that some of my URLs won't load. I just get a long wait while the server tries to respond and I never end up getting a response. Or at least I'm not waiting long enough to see it (but I've waited for durations of minutes).

I only seem to have the issue so far with one of my Rails models. That model is a little quirkier than others since several of the database fields are serialized arrays. I'm guessing that the problem I'm seeing would be more related to the database adapter though than having anything to do with Glassfish.

I'll have to look into it further before I can use JRuby/Glassfish for actual production.

-A

By: Vivek Pandey
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 18:57
Arun,

Infact rootcontext '/' should not be an issue. The trailing '/' I mentioned that applies only to a non-root context path, such as 'myapp'.

Anyway, since you are working on it and if you think root context '/' is not working please open a bug on gem.

-vivek.

By: Vivek Pandey
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 18:55
Cool! Glad it worked for you:)

By: Arun Gupta
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 18:52
Cool, I was about to try -c option. But seems like running on root context is still an issue.

What's the purpose of VirtualHost rule ?

Anyway, I'm converting this discussion in a blog.

By: Aaron Reichman
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 18:49
Before I read your reply I was actually just trying the -c option. :)

That did work. Since my Apache rewrite was trying to redirect everything from /myapp to Glassfish, I needed to tell Glassfish to start with /myapp as the root. Now all of the paths (links, CSS, etc.) work properly.

So in summary, here's my setup now:

http.conf:
<Proxy balancer://myapp>
BalancerMember http://127.0.0.1:8080
</Proxy>

<VirtualHost *.80>
...
RewriteRule ^/myapp(.*)$ balancer://myapp%{REQUEST_URI} [P,QSA,L]
</VirtualHost>

glassfish gem:
glassfish -e production -p 8080 -c "/myapp"

Thanks for your help!

-A

By: Vivek Pandey
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 18:34
Ok, so you have the app deployed on mongrel using 'myapp' prefix. On glassfish you can do the same using -c option.

For example,

$ glassfish -c /myapp will mean your app is available at

http://localhost:3000/myapp/

I wonder if there is any leftover of mongrel config somewhere in apache config where 'myapp' prefix is somehow present.

By: Aaron Reichman
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 18:25
Vivek-
1. My mongrel configuration does use a prefix so my mongrels are available at http://localhost:8000/myapp and http://localhost:8001/myapp. They are not available at simply http://localhost:8000 etc.

2. All my log shows is the com.sun.grizzly.config.GrizzlyServiceListener message. I'm assuming this means the Glassfish server is now ready. After that I get the typical Rails messages to show my controller action loaded successfully. But there are no messages about images from my CSS files not loading.

3. The app is running on another intranet that I don't have access to from here. But if there are particular logs you'd like to see, I can try to summarize any messages here.

4. Tried with and without trailing slashes to no luck. Looks like Arun has the same problem.

5. Another odd thing I just noticed is that while my app sort of loads, all links seem to be broken. A rails generated link (using the link_to helper) created a link to http://server.com/new_link instead of http://server.com/myapp/new_link. So it seems as though my entire Rails app (except for the start page?) thinks it is running at the server root, instead of in a subfolder of root. If that's the case, that's probably why my CSS won't paths won't load.

Thanks...

-Aaron

By: Arun Gupta
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 17:53
I tried JRuby/Mongrel and JRuby/GlassFish with the following entries:

<Proxy balancer://glassfishgem>
BalancerMember http://localhost:3000
</Proxy>
ProxyPass /railsapp balancer://glassfishgem

for a simple scaffold. The stylesheets were not picked up for the generated scaffold page, tried with and without "/".

However the default Rails page was shown correctly at "http://localhost/railsapp/"; with image and CSS, but "http://localhost/railsapp"; (no trailing /) picked up only the CSS but no image.

Vivek, the visual cue between "http://localhost:3000/runlogs"; and "http://localhost/railapp/runlogs"; indicate that CSS is not picked. Here are some httpd logs:

-- cut here --
[Thu Jun 11 10:52:15 2009] [6566:1879615232] [debug] map_uri_to_worker_ext::jk_uri_worker_map.c (1035): Attempting to map URI '/stylesheets/scaffold.css' from 1 maps
[Thu Jun 11 10:52:15 2009] [6566:1879615232] [debug] find_match::jk_uri_worker_map.c (849): Attempting to map context URI '/*.jsp=loadbalancer' source 'JkMount'
[Thu Jun 11 10:52:15 2009] [6566:1879615232] [debug] jk_translate::mod_jk.c (3361): no match for /stylesheets/scaffold.css found
[Thu Jun 11 10:52:15 2009] [6566:1879615232] [debug] map_uri_to_worker_ext::jk_uri_worker_map.c (1035): Attempting to map URI '/stylesheets/scaffold.css' from 1 maps
[Thu Jun 11 10:52:15 2009] [6566:1879615232] [debug] find_match::jk_uri_worker_map.c (849): Attempting to map context URI '/*.jsp=loadbalancer' source 'JkMount'
[Thu Jun 11 10:52:15 2009] [6566:1879615232] [debug] jk_map_to_storage::mod_jk.c (3428): no match for /stylesheets/scaffold.css found
-- cut here --

I think it's something to do with mod_proxy_balancer configuration and further playing with that.

By: Vivek Pandey
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 16:52
It should have just worked. Couple of things:

- Are you deploying mongrel apps with any specific context path or they are also visible to http://localhost:8080?

- Do you see any log statement that the images could not be resolved and what path you see?

- Some HTTP log would be useful.

- Can you change the following in apache config and try:

ProxyPass /my_rails_app http://localhost:8080/
ProxyPassReverse /my_rails_app http://localhost:8080/

I think I have seen issues related to missing trailing '/' and resolving images.

-vivek.

By: Aaron Reichman
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 16:38
Arun-
Yes, the images are visible with MRI/Mongrel when using mod_proxy and mod_proxy_balancer. I can successfully view my app at http://server.com/my_rails_app, where my_rails_app is actually running via two mongrels on ports 8000 and 8001.

Likewise, with Jruby/Glassfish gem, I can successfully view my app and all images at http://server.com:8080. I just can't get my app or its images to run correctly at the old URL of http://server.com/my_rails_app.

I'm not sure what the equivalent Apache rewrites are for Glassfish that will yield the same results as the rewrites that I had for Mongrel cluster.

By: Arun Gupta
RE: Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 16:25
Hi Aaron,

Are the images visible with MRI/Mongrel and/or JRuby/Mongrel ?

I've not played with mod_proxy_balancer but here are couple of entries that show how to front-end GlassFish with mod_jk and nginx:

mod_jk: http://blogs.sun.com/arungupta/entry/totd_67_how_to_front

nginx: http://blogs.sun.com/arungupta/entry/totd_81_how_to_use

I'll try to play with mod_proxy_balancer and write something about it as well.

Thanks,
-Arun

By: Aaron Reichman
Glassfish gem with Apache Virtual Host [ reply ]  
2009-06-11 16:20
I now have our web server configured to run one of our Rails apps in production mode, but I have an issue that I'm not sure how to resolve.

We are currently using a Solaris 10 server to host several non-Rails apps with Cool Stack 1.3 (we haven't migrated to Glassfish Web Stack 1.4 yet, but plan to do so in the near future). Previously, our Rails apps ran using Mongrel cluster and Apache 2.2's mod_proxy_balancer. We had two simple Apache rewrites in the http.conf file (using a Vitual Host block) to redirect traffic for our Rails app to the Mongrel cluster and that has worked well. These were basically the same rewrites documented in Dave Thomas' Agile Web Dev with Rails book.

Now, I have migrated our Rails app to the Glassfish gem and the app is successfully running on port 8080. What I can't figure out is how to reconfigure our Apache config file to redirect all traffic for this Rails app to the Glassfish gem server instance.

I attempted to add the following lines to my Apache config file (inside the same Virtual Host block that we've been using):

ProxyPass /my_rails_app http://localhost:8080
ProxyPassReverse /my_rails_app http://localhost:8080

That works somewhat, as the Rails app is now visible at its normal http://localhost/my_rails_app location. However, none of the URLs for the images within my CSS files for the Rails app are redirected. I'm guessing this is because they all use relative paths and the Apache proxy isn't detecting them and therefore isn't forwarding them.

Is there something esle I can add to the Apache config file to ensure that all requests associated with my Rails app are properly redirected to the Glassfish server?