Running jRuby + Rails inside of Tomcat - ruby-on-rails

I am currently using a platform where multiple web applications must interact with each other in a frameset. This set of web applications and the frameset is hosted on Tomcat.
Now the application we're working on is developed with jRuby and Rails. Is there anyway I can run my development environment inside of Tomcat similar to just running the jRuby -S Rails Server command so I can effectively debug?
The only way I've found is to generate a war using warble and then modifying the exploded war which seems really hacky. Any thoughts?
EDIT: I think my best bet is to generate a war, gut it, use symbolic links and figure out what gems / libs I need to copy from the war generation process. It's the best way I can think of.

one option to explore: deploy a little servlet to Tomcat which returns
HTTP/1.1 301 Moved Permanently
Location: http://localhost:3000

So far the best solution I have found is to setup a reverse proxy with Tomcat and point it to the Rails development server. This allows it to run, as expected on the client side, while still giving me debug control.
When I get a chance to do some more testing I'll edit my answer to include additional information.

go to the webapps folder in tomcat where you have deployed the war file, then find the web.xml file inside the expanded war file
The path to this file is generally /var/lib/tomcat7/webapps/your-project-here/WEB-INF/web.xml and inside this file you should find the
Changing this is one way to go about.
<context-param>
<param-name>rails.env</param-name>
<param-value>production</param-value>
</context-param>

Related

Capistrano and XSendFile configuration

I am trying to configure Rails production server with Apache 2.2, Passenger 4.0.59 and XSendFile 0.12. Application is deployed via Capistrano.
Deployed application produces (maybe large) PDF to #{Rails.root}/tmp and serves this file using send_file.
The problem is that Capistrano uses symlinks to point to currently deployed version of application. XSendFile on the other hand dereferences symlinks and refuses to serve a file if its real location is outside document root even if it is allowed by XSendFilePath. Apache's error.log states:
(20023)The given path was above the root path: xsendfile: unable to find file: /resolved/path/to/file.pdf
Everything works well when I set PassengerAppRoot and XSendFilePath to the real location of current version of application, without symlinks on the path. But it's OK until next deploy, which requires apache reconfiguration. Not very useful.
How should I configure Capistrano deploy and XSendFile parameters to make it work together?
I tried solutions with ln -nFs described in Capistrano & X-Sendfile and in mod_xsendfile with symbolic links but none works.
I finally managed to make it work. A few tips for the ones who will have problems with XSendFile
I set XSendFilePath to user's $HOME, there are no symlinks on the path to $HOME, so it works. I can accept this from functional and security point of view, but it is obviously a workaround.
Be aware that XSendFilePath is sensitive to paths containing multiple slashes /like//this. I am using apache macros and while concatenatingXSendFilePath parameter from a few macro parameters I put some obsolete slashes. This caused XSendFile to refuse to send files.
Good luck!

How to configure Rails app for deployment to Tomcat

I have a Rails app that I package as a war file for deploying to Tomcat using Warbler. And it works, but the problem is I don't know how to configure the runtime properties like secret_key_base. I use the standard setup of using secrets.yml, with production variables coming from environment variables. But I don't know how to set the variables while still keeping them out of source control.
Ideally I'd still like to be able to deploy the war file automatically, by just dropping it into the webapps/ directory, but I suppose I could edit the server config file? Or is there a better way of handling this?
either do it the same way as you would in a Rails server ... let it read from ENV (of course you will need to make sure Tomcat has the environment variable set).
alternatively you can set it in a web.xml if you're packaging and than do a $servlet_context.getAttribute('foo') in secrets.yml ... or read it from a file location that only the server's tomcat username can access etc.
sky is the limit here - you basically need to decide what fits your deployments the best.

How to Tell Engine Yard to Not Delete a File in the .gitignore

To give you some context, I'm trying to use Figaro to safely add in environment variables without having to worry about security risks. The problem is is that I can't seem to get Engine Yard to play nice with production.
I went and did a touch application.yml and then vim application.yml, i, and then command+v to insert that api keys and what not. I know the ENV['VARIABLES'] work because of development and all my rspec and cucumber tests (which utilize the APIs), passed.
When I've got everything ready, I add within the .gitignore:
# Ignore application configuration
/config/application.yml
Afterwards, I deploy the site. I open it up and data isn't going to the APIs anymore. OK...
cd into config and discover application.yml isn't there anymore. Paste it back in... Redeploy the site since now it understands it has to ignore that file and I'm not seeing changes on production. Check back... and its gone again!
Stumped on what's going on.
Simply putting a file into your deployed application's filesystem will not work because you get a clean environment each time you deploy. EngineYard cannot know that you want that particular file copied to that particular location without a little bit of extra work.
Their official recommendation is to put your YAML configuration files in /data/<app>/shared/config and symlink them to /data/<app>/current/config each time you deploy using deploy hooks.

Rails application issue after deployment - 404 error

I'm new to RoR.
I was able to install Rails and host it in Webrick (Sample App with "Welcome" controller) in my windows.
Now i have a Unix Weblogic Server along with a dedicated domian.
After exporting the .WAR file using Warbler, i accessed the Oracle Admin Console from where i deployed the .WAR file in the dedicated domain. I did all this for the Sample app with only the Welcome controller in it.
But even after deploying the WAR file, on accessing the Domain along with the Port Number (:9002) i ended up with 404 file not found error On looking at the server logs,there wasn't any records relating to any error. The Application must have been deployed properly. I assume that i must have missed out on some basic configurations in the routes.rb or similar files before deploying. Can anyone Guess what are all the possibilities and if possible can anyone help me by pointing to any tuts that cover the Steps to be carried out for configuration before deployment. do i need to install both JRuby and Rails inside the server before depolyment?
I can't really guess with Eror 404 only.
You can try mapping your rails app rack config to a different base_uri.
All you need to do is wrap the existing 'run' command in a map block
try doing this in your rails 'config.ru' file:
map '/mydepartment' do
run Myapp::Application
end
Now when you 'rails server' the app should be at localhost:3000/mydepartment .
Not sure if this will give you the desired outcome, but worth a try.
One more thing you also add this to your config/environments/production.rb and config/environments/development.rb (if on production mode):
config.action_controller.asset_path = proc { |path| "/abc#{path}" }
otherwise when you call your helpers such as stylesheet_link_tag in your views, they will generate links without the "/abc".
Also, find some guides you may refer for good support.
JRubyOnRailsOnBEAWeblogic.
Use JRuby with JMX for Oracle WebLogic Server 11g
Let me know if it is not resolved.

Where are the logs for a Rails app packed using Warbler?

I'm using Warbler to pack a Rails application into a WAR. I've deployed it to a JBoss server and it seems to works.
However, I'm getting the classic 500 error on Rails saying "We're sorry, but something went wrong.".
Usually, I'd take a look at logs/production.log to find out what's wrong, but since the project is WARed, I can't access it. The question is, where are the logs written when the Rails app gets warbled?
JRuby-Rack, the servlet container adapter that Warbler bundles, is set up by default to redirect Rails logs to the servlet container using the javax.servlet.ServletContext#log method. So exactly where the logs appear is server-specific. For Tomcat, they should be in catalina.out, for GlassFish, server.log.
If you still don't see error messages in the log files, there could be a bug somewhere along the way that is swallowing the error. Feel free to open a problem report for JRuby-Rack at http://kenai.com/jira/browse/JRUBY_RACK.
Although this question is pretty old and has been answered already, but I had been facing similar issue with Sinatra application which was warbled and deployed in Tomcat. The catalina.out (or tomcat logs folder) was not spitting out the logs at all. I finally found that the logs reside in the deployed application's WEB-INF folder itself.
For example
{TOMCAT_BASE}/webapps/{WEB_APPLICATION_PATH/WEB-INF/log/production.log
This had been a mystery to me for quite sometime.

Resources