# Starting ruby on rails with multiple applications

**URL:** <https://www.ruby-forum.com/t/starting-ruby-on-rails-with-multiple-applications/122104>\
**Category:** Rails\
**Created:** [December 4, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/starting-ruby-on-rails-with-multiple-applications/122104 "2007-12-04T17:13:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 4, 2007, 5:13pm UTC](https://www.ruby-forum.com/t/starting-ruby-on-rails-with-multiple-applications/122104/1 "2007-12-04T17:13:00Z")

</div>

Hi,

I’m using Fedora Core 5 Linux with the latest version of Ruby on  
Rails. I’m just learning it, but let’s say I’ve created two rails  
applications in the directories

application1/  
application2/

I can “cd” to application1 and run “ruby script/server” to start that  
application. But then must I do this for “application2” as well? Is  
there a generic way of starting all ruby-on-rails applications at  
once?

Thanks, - Dave

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 4, 2007, 5:36pm UTC](https://www.ruby-forum.com/t/starting-ruby-on-rails-with-multiple-applications/122104/2 "2007-12-04T17:36:31Z")

</div>

I had a need of something like that once, so I came up with this scheme:

In each rails folder, I create three files:  
app\_start  
app\_stop  
app\_restart

app\_start and app\_stop contain the shell script calls necessary to  
start the particular application. So if you are using Mongrel,  
app\_start might look something like

mongrel\_rails start -p 3010 -e production -d

and app\_stop would look like

mongrel\_rails stop

That way each app\_start/stop pair is specific to the application, but  
general enough to be called via a universal script. Then I created  
the universal script that would descend into the directory where all  
the rails apps were (/var/www in this case), and if there was an  
app\_start, exec it. I named the script rails\_ctrl and it looks like  
this:

#! /usr/bin/ruby

# This script is used to launch all rails apps after a restart. It

assumes that each

# app will have a file named app\_start in the project’s root

directory. This file needs

# to call mongrel\_rails or mongrel\_cluster with the proper parameters.

action = ARGV.at(0)  
action ||= ‘’  
action = action.downcase

app = ARGV.at(1)

if ![‘start’, ‘stop’, ‘restart’].include?(action)  
puts “rails\_ctrl: Invalid action: #{action}”  
exit  
end

root\_dir = ‘/var/www/’  
dirs = Dir.entries(root\_dir)  
dirs.each do |dir|  
if ![’.’, ‘…’].include?(dir) && dir == (app || dir)  
d = “#{root\_dir}#{dir}”  
if File.directory?(d)  
f = “#{d}/app\_#{action}”  
if File.file?(f)  
Dir.chdir(d)  
puts “Performing #{action} action on #{dir}…”  
system(f)  
end  
end  
end  
end

This was just hacked together one day to suit my purposes, so it may  
have some holes in it. Feel free to take it and modify to fit your  
environment.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 4, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/starting-ruby-on-rails-with-multiple-applications/122104/3 "2007-12-04T18:05:02Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Hi,
> 
> I’m using Fedora Core 5 Linux with the latest version of Ruby on  
> Rails. I’m just learning it, but let’s say I’ve created two rails  
> applications in the directories
> 
> application1/  
> application2/
> 
> I can “cd” to application1 and run “ruby script/server” to start that  
> application. But then must I do this for “application2” as well?

Sure.

> Is there a generic way of starting all ruby-on-rails applications at  
> once?

Rails applications don’t necessarily need to be “started”. Your  
webserver can have virtual hosts set up so that [app1.yourdomain.net](http://app1.yourdomain.net) and  
[app2.yourdomain.net](http://app2.yourdomain.net) point to the Rails applications under application1  
and application2.

Then your webserver will take care of running those Rails applications  
as requests come in to [app1.yourdomain.net](http://app1.yourdomain.net) or [app2.yourdomain.net](http://app2.yourdomain.net)

Look up “lighttpd virtual hosts” or “apache virtual hosts” on Google.

Stephan
