How do I setup multiple rails applications for development? - ruby-on-rails

For the site I am currently working on we have 2 Rails 3.2 projects. One project is basically an API, and the other is a web front end. In order to develop on the web front end I need to have the API project running. I've tried using the foreman and subcontractor gems to manage this but it doesn't seem to work. Both projects run the Thin application server and have their own RVM gemsets. We also run Nginx in production.
How would you go about managing this setup for development? I want there to be 1 command to fire up everything, similar to how Foreman works.
Requirements:
RVM Support
Thin for development
One command I can run from the API application to start both applications
Cannot using Pow (it always seems to get hung up and is incredibly slow)
Setup should work for other developers with minimal setup (easily scriptable)
Works on OSX
Thanks!

tmuxinator allows you to easily configure a tmux session that can be launched with a single command containing any number of windows (tabs) and executes commands in each window (like starting a server). Just configure it to load the appropriate gemset for the appropriate rails server.
https://github.com/aziz/tmuxinator

another, very cool alternative to the tools you've mentioned is Invoker.
it's worth checking out, as it allows to run multiple processes at once (as well as terminate them), like foreman does and it offers .dev domain which mimics pow behavior.

Related

Ruby on Rails app : from Heroku to a local server : what are the main steps?

My Ruby on Rails app (basically a commenting and voting system) has been deployed and currently runs on Heroku. I need to deploy it on a local server to ensure an optimal performance for a customer-organized event in a location where the internet bandwidth is too low and unpredictable to support the 100+ simultaneous users.
Just as Ruby, Rails, Javascript, JQuery, AJAX and CSSs were new to me a few months ago, going local is something new I need and am eager to learn (which should also allow me to deploy onto a dedicated or virtual private server if needed).
The following elements are obviously on the way : choosing an operating system, installing Ruby on Rails, a web server, a database engine and deploying my app code and data of course but I need help to make sure I do not forget anything and really understand how all of these elements must be tied together to get my app running.
At a reasonably high level, starting with my app code, could you please share your experience and tell me the steps I need to take from scratch to have it run on a local server ?
If you have a Mac, then you're already most of the way there. I do all of my Rails development on OS X. The steps from there are pretty easy.
Install Homebrew. This will help you quickly install any dependencies on the Mac that your Rails app needs (such as a database). Since you're on Heroku, you're likely using Postgres. So with Homebrew, you can install Postgres via brew install postgresql.
Copy your app code somewhere that makes sense. I have all my apps inside my ~/Projects directory.
Recommended: Install RVM. This will help keep gemsets unique to projects and keep your global gemset clean.
If you're using bundler, do bundle install within your app's directory.
Within the app directory, do: rake db:setup (Note: This may require prepending bundle exec)
Start your server. I tend to use Unicorn (see Heroku's deployment with Unicorn for even more details), so this would just be unicorn. Else, rails s works as well.
Those are the high level steps to get a local server running.

Rails 3 and Thin. Is there a way to execute a file after thin starts?

I currently have a rails 3.2 app that I am going to use thin as a web server for. I haven't found a way or know if what I am even attempting is possible which is why I came here to ask. What i'm trying to do is after I start my rails app with the usual bundle exec thin start to afterward execute a ruby file/script to load up another web event based mini application(pure ruby non web framework) that will uses the same server/ data store as the main rails app. Is there such a hook either with thin configs or rails start up configs to accomplish such a thing?
-edit-
to clarify, the mini application is within the rails app in its own directory, it is not an external app which is why it will share resources.
Have you tried Foreman? It is a tool used for describing and launching all the individual processes your application requires (potentially covering both your main web server, thin, and the secondary Ruby process you mentioned). You would just install Foreman, then write a Procfile describing both processes to run at startup.

How to install Ruby script on server?

I apologize in advance for the fairly simple question.
I am familiar with PHP, but am trying to install this Ruby script on my server for the first time. It's an open source script that I've forked from github, but unfortunately does not have any instructions. I have Ruby on Rails, and MongoDB installed already.
Does anyone know what the beginner steps are to get started? Should I upload everything via FTP to the public directory, or is there something else to this?
Most Rails projects are much better served by having a proper deployment strategy. Typically this involves making your own repository, easily done by forking that existing application, and cloning that on to your server using git. To make changes in the future, do your work on a development copy, push that into the repository, and pull down the changes on the server.
Unlike PHP where many parts of the application can function independently, Rails applications tend to be far more integrated and uploading it piece by piece is not going to work in the long run.
Rails applications can run stand-alone using the provided rails server tool but this is really only intended for light-duty testing or development work. A more permanent solution is to use something like Passenger to do the hosting for you.
Passenger will take care of launching your application when calls are made to the site you've configured in Apache or nginx, depending on which you end up using. Passenger is popular because it's quite easy to get running.
There are other approaches like unicorn if you're feeling more adventurous.
When you make changes to your Rails application in production mode you will have to create a tmp/restart.txt file in the main application directory to tell your web server to restart the process. This is not a requirement in development mode.
Due to the relative complexity of this process once you include all the various steps, you will probably want to use a deployment automation tool like capistrano.

How to run rails website permanently on Mac OS X

i've developed small web app for personal use with Ruby on Rails. Now when i want to use it I open Terminal and run ruby script/server to run mongrel then i go to Safari and type localhost:3000 to see my app.
I'd like to have this site start automatically on startup of mac and possibly to use some other URL.. preferably just http://myapp/
I come from C#/asp.net world and don't know much about apache/mongrel stuff.
Do you know any step by step tutorial how to configure rails/mongrel/apache on mac os x leopard to work together and run after startup, please? (I have apache running, which was done just by checking checkbox in system preferences/sharing)
This page by apple should have all the information you need:
http://developer.apple.com/tools/deployonrailsleopard.html
The easiest method would be to install Passenger Phusion / mod_rails for Apache. This will allow you to use sidestep the usage of Mongrel/Thin/etc and deploy apps much like php (stick it in a folder and go).
If you want to run it on Mac OS X you can simply setup your webserver, I recommend nginx with Phusion's Passenger, and your database server to start on boot, that way whenever your computer has to restart it will have your site running. Of course if this is a laptop that will be changing networks and needs to be accessed by other people I would recommend getting a proper VPS for it, come to think of it, I would recommend that anyway if this is supposed to be a production environment.

Running multiple web frameworks on one machine?

I want to start experimenting with all these different web frameworks that are available. I was wondering if they could all run in one machine at the same time?
I know that all my database services can all run at the same time, along with the Javascript frameworks, but what about something like Rails and Java applications? Can those play along with each other? Will Apache handle all of this for me?
Yes, since almost any language framework runs as normal code for the language, simply providing structure for applications you write, they can coexist well with other frameworks for the same or other languages. You can certainly run Rails and a Java framework on the same machine - you could even run Rails on JRuby and a Java application server
It sounds like you're just getting started programming. I would recommend learning some of the basics first. For instance, if you want to learn Ruby, try the Pickaxe book, write some simple scripts, then move on to a ruby web framework like Sinatra or Rails. You'll have a better understanding of the difference between a language and framework, how each is installed and run on your machine, etc.
The easiest way to begin experimenting is to use the development server that is included with the various frameworks and run the server on a different port (not 80). For Rails, this is done via:
ruby script\server
which will start a server on port 3000.
Other frameworks use other approaches. Most tutorials for Ruby and Python frameworks (with which I am most familiar) will include instructions on how to start a development server like this.
I don't see why not. It really depends on how the frameworks are deployed and in what containers. If they use separate containers (e.g. tomcat vs apache) you'll need to make sure that the containers are configured to use different ports since many web containers use 80 or 8080.
If you plan on running them all in the same container (e.g. Apache) then I would think they'd be fine, since each one can be treated as a separate web application and deployed to a different location in your document root.
For the most part, it'll probably be trial and error. I don't know much about how Rails interacts with Java, but I've run Grails and Java applications together easily myself with few problems.
I run Rails, PHP, and Java with one Apache server. Except for what felt like a ton of apache config munging when I set it all up, it's been fine. I'm not much of a sysadmin, so it took me a few days to get everything running right.
PHP, Java and Rails all have environments that let you run independent servers and save complex configuration.
Java you can use Tomcat or Jetty.
Rails comes with Webrick, which is fine for development.
PHP has XAMPP (or MAMP if your on the Mac) gives you a complete stack.
I run Rails and ASP.NET MVC on the same Machine and I just set my local servers to run on different ports. But usually the default setup (e.g. Rails on port 3000) will not conflictwith each other, plus each framework usually has its own way to run (LAMP, Webrick, Montgrel...) so you should be fine.

Resources