myRails App Launcher

Once I had multiple rails applications on my computer for development, I found it rather cumbersome to manage the start/stop/restart of these apps. Part of it was remembering which port each one was supposed to run on. I like each app to run on a separate port so it never matters which ones I need to fire up and have running at the same time. The other hassle was clearing log and pid files when I needed to restart an app.

I’m not fond of a lot of command line typing, and after a few attempts at using bash scripts for each project to reduce what I had to type, it finally dawned on me to unify everything into a single ruby script with a simple setup config.

Usage

Here’s how it works at the command line:

To start a particular project named gw (for my website):
$ myrails.rb gw --start
or just simply:
$ myrails.rb gw
I suspect you can now guess what it takes to stop an app:
$ myrails.rb gw --stop
I also have:
$ myrails.rb gw --stop_all

For restart, I just use the start command. If the app is already running, then the script stops it, and starts it up again. Before every start, the script cleans up the log and pid files, so there’s never a need to worry about that. Running a start command for an app, you’d see something like the following in Terminal when a site is restarted:

$ myrails.rb gw

Stopping rails...
Sending TERM to Mongrel at PID 22367...Done.
Clearing logs...
Removing stray pid...
Done

Starting rails (3015)...
Done

If you can’t remember your project names, you can leave out all parameters, and myrails will list all the project names from the config file.

$ myrails.rb

Please specify one of these projects:
gw, turnfast, araelium, mickey, donald, goofy

Setup

I put the myrails.rb script in /usr/local/bin (I’m an OS X user), and a config file myrails.conf in /etc.

The conf file is used to define project parameters for myrails.rb as a YAML hash of hashes. Each project definition require three elements:

  • :project_name -- a label to use in the command line (e.g. myExample)
  • :app_root -- the path to the folder containing the rails application
  • :port -- a port number to run the rails app on

The file would look something like this

--- 
:default
  :app_root: /Users/greg/Sites/railsplay/railsplay_src
  :port: 3000
:myExample
  :app_root: /Users/greg/Sites/myExample/example_src
  :port: 3001

Wrapup

That’s it. I suppose some folks might use rake, but I like having everything in one place so I can see the port numbers being used, and so it’s easier to reorganize in case I move projects, etc.

The script is specific to Mongrel, so if you’re using something else, you could alter it for your situation.

Anyway, I find it very useful, easy to remember how to use, and quick to use and maintain.

 
 

Download (2.9 KB) : myrails_launcher.zip

The myrails.rb script, and a sample config file.