For this article I used the chapter Setting Up A Development Environment in Agile Web Development with Rails, version 2.0, plus these two articles.
Capistrano working together with Mongrel allows you to deploy and restart Mongrel clusters quite nicely.
Configure Mongrel Cluster
First you need to configure a Mongrel cluster. Here is an example that creates three Mongrel instances starting at port 8000, listening on the local interface, 127.0.0.1.
$ mongrel_rails cluster::configure -N 3 -p 8000 -e production -a 127.0.0.1 \ -c /usr/local/rails/production/current \ -C /usr/local/rail/production/current/config/mongrel_cluster.yml
Here is how the created file looks like.
--- cwd: /usr/local/rails/production/current log_file: log/mongrel.log port: "8000" environment: production address: 127.0.0.1 pid_file: tmp/pids/mongrel.pid servers: 3
Note that for testing purposes you should comment out the address line.
#address: 127.0.0.1
We specified listening only on the local interface for security purposes but for testing the cluster we need to access it directly via its remote IP address.
Setup Capistrano
Next you create a stub Capfile and config/deploy.rb.
$ capify .
Now you can get a list of all the tasks that are available and there quite a few.
$ cap -T
Next modify config/deploy.rb like in this example.
require 'mongrel_cluster/recipes' set :application, "foobook" set :repository, "http://example.com/svn/foo/trunk/foobook" role :web, "192.168.3.17" role :app, "192.168.3.17" role :db, "192.168.3.117", :primary => true set :deploy_to, "/usr/local/rails/production" set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml" set :svn_user, "fkim" set :svn_password, "fkim" #set :user, "root" # defaults to the currently logged in user set :scm, :subversion # defaults to :subversion set :svn, "/usr/bin/svn" # defaults to searching the PATH
Deploy using Capistrano
Now run setup which will create the directories remotely.
$ cap deploy:setup
Check dependencies.
$ cap -q deploy:check
Deploy for the first time.
$ cap deploy:cold
Everytime after you can deploy like this.
$ cap deploy
Starting and Stopping Mongrel using Capistrano
If you want to just start the mongrel cluster.
$ cap mongrel:cluster:start
If you want to just stop the mongrel cluster.
$ cap mongrel:cluster:stop
And that’s it.
Not that bad at all. Starting and stopping mongrel was the biggest issue for me. I realized that I did not need to create the spin script as suggested in the Using Capistrano with Rails article. If the mongrel configuration is correct then Capistrano will correctly start and stop it and you can use the above cap commands to test it.
Pingback: betweenGo » Configuring Apache to work with a Mongrel Cluster
This is a very simple and clean tutorial. The only problem was that mongrel_cluster recipes where not working for me.But anyone with the same problem simple put the code from [http://weblog.imapenguin.com/articles/2007/11/27/capistrano-2-0-and-mongrel-recipies] at the bottom of your deploy.rb and remove require ‘mongrel_cluster/recipes’
Enjoy the magic .ST
Pingback: Delicious Bookmarks for February 8th through February 9th « Lâmôlabs