Deploying a .war made by Warbler to Tomcat - ruby-on-rails

I was trying to simply make a .war file and put it into Tomcat's webapps directory. Simple, right? :)
What is puzzling me is that the directory structure of a JRuby app has the index.html file somewhere far in the application structure and Tomcat just can not find it by default.
Here is what I get when I point my url to the Tomcat install of the application:
http://128.48.204.195:8080/blog/index.html
How should I structure the build/deploy of a JRuby application so that it works on Tomcat when unwrapped out of a .war file?

first try http://128.48.204.195/blog
that will serve the root route (if defined in config/routes.rb) or a error saying nor route.
If you see this: http://krokinet.files.wordpress.com/2010/11/rails-welcome1.png
there is a default index.html file in /public/index.html
that file is generated with the app and you should remove it once your done an initial 'smoke test' (running your newly generated app the first time).
More information on the root route here: http://edgeguides.rubyonrails.org/routing.html#using-root

Related

Finding the application path after deployment

I successfully deployed my Rails application fireworks_app with Dokku in a Ubuntu 18.04 LTS machine, and now I would like to add a logrotate file for my Rails logs. What is the path of my application and thus of my log files? There is a /home/dokku/fireworks_app folder but this folder contains only the following items:
$ ls
CONTAINER.web.1 DOCKER_OPTIONS_RUN HEAD URLS cache hooks maintenance objects
DOCKER_OPTIONS_BUILD DOKKU_SCALE IP.web.1 VHOST config info nginx.conf refs
DOCKER_OPTIONS_DEPLOY ENV PORT.web.1 branches description letsencrypt nginx.conf.d
I suppose somewhere in the system there is a folder containing my application with the known Rails file structure, but I cannot find it.
Inside your rails application you can do something like Rails.root to get the path to the root directory of your project.
For instance, if the log files are in fireworks_app/lib/log/ you could do Rails.root.join('lib','log','log_file.log') to get the path to that file.

Changing Directory Names in a Rails App

I'm relatively new to Rails as well as using PassengerPhusion. I am running an Ubuntu server on Azure, and have the demo app that Passenger provides working fine. I've even changed the text on the homepage.
My question is this:
In my directory, the file directory's name for the app is passenger-ruby-rails-demo and while I am experimenting, i am changing the name of the directory to something like passenger-ruby-rails-demo-test and it returns an error message when viewing fleetpro.cloudapp.net.
I've tried looking through files trying to figure out how this is routed but haven't had any luck. Is there a file within the Rails installation that is telling Passenger to be inside the specific passenger-ruby-rails-demo directory? Pretty newbish question, but it is really bothering me!
I'm not sure about how the naming convention works in regards to the root directory name of your app "passenger-ruby-rails-demo", but I believe the name of that directory is important to running your Rails app, and might have to do something with the name of the module in your config/application.rb file which is named after your Rails app.
There is a solution though: use gem rename.
Add gem rename to your Gemfile and run bundle install.
Then in your app's root directory, run this:
rails g rename:app_to New-Name
This will basically "clone" the app with your new name. You may have to check to make sure all your config files are present afterwards, but from my experience using it, it was a quick breeze. You will most definitely have to push the new renamed app back to git or Azure.
EDIT
As an example I renamed a Rails app to show what you could expect from the output after running the command:
The Rails app's name isn't the problem, it's the PassengerAppRoot switch you'll be using:
PassengerAppRoot /path/to/your/app
Rails doesn't actually care which folder it's put into, so renaming Rails won't fix your problem.
Renaming Rails only changes the internal class references within your application (things like Rails.application.name which have very subtle implications for your app).
In your Azure server, you'll need to locate either your .htaccess / httpd.conf / nginx.conf file, and change the PassengerAppRoot to your new path. This should resolve the issue.

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!

Running jRuby + Rails inside of Tomcat

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>

Warbler: Where are my images

I'm using Jruby and Warbler to deploy a Jruby on Rails application to a Tomcat server. I can see all of my images when I deploy the server with Webrick: jruby -S server/script. However, when I create a .war file out of the rails directory using jruby -S warble and deploy to Tomcat, none of my images show up on the tomcat server. I noticed that image location has changed to the root of the directory in the war file.
It seems that /images/picturename.jpg would be appropriate, but my images are not showing up.
"not showing up" -> 404? You said you noticed the image location changed, did you check that the specific images are present? (jar tf myapp.war will show you.)
Did you deploy your war under a context path? I.e., if the home page is at /myapp/, then images will be at /myapp/images/picturename.jpg. JRuby-Rack tries to adjust the Rails asset paths for you to include the context path, but there may be some cases where it doesn't. You may want to resort to just setting config.action_controller.asset_host in config/environments/production.rb to '/myapp' as well.
Did you set up the correct symlinks to your images folder?
f.e. /var/www/website.com/current/20090807200123/public/images --> /var/www/website.com/shared/public
?

Resources