Tuesday, October 03, 2006

pound and mongrel_cluster

In order to easily manage the development/deployment via Capistrano, it made sense to also be running mongrel_cluster automatically. This way deployment is real-time with instant results.


gem install mongrel_cluster capistrano --include-dependencies


Then install pound via emerge/yast. Edit the pound.cfg file:
(this still doesn't seem to be working)

ListenHTTP
Address 0.0.0.0
Port 80
Service
BackEnd
Address 0.0.0.0
Port 8000
End
BackEnd
Address 0.0.0.0
Port 8001
End
BackEnd
Address 0.0.0.0
Port 8002
End
Session
Type BASIC
TTL 300
End
End
End


Start pound and add it to startup:


/etc/init.d/pound start
rc-update add pound default



Next, railsapp/config/mongrel_cluster.yml would look like:


cwd: /home/build/deploy/current
port: "8000"
environment: development
address: 0.0.0.0
pid_file: log/mongrel.pid
servers: 3



Initialize capistrano for railsapp:


cap --apply-to /path/to/railsapp MyApplicationName


Now that capistrano has been initialized, update the config/deploy.rb file adding:


set :mongrel_conf, "#{current_path}/config/mongrel_cluster.yml"


Update the other properties as necessary, paying particular attention to:


role :web, "someserver.yourinternaldomain.local"


The servers will have to be contactable by the exact name placed in the quotes.

Update the remote variables:


set :deploy_to, "/home/build/deploy"
set :user, "build"
set :keep_releases, 5

Be sure to have the "build" user's password on hand since it'll be necessary for capistrano commands.

Ensure capistrano is working with:


rake remote:exec ACTION=setup


Check that the target server has the releases and shared directories created, if so, capistrano worked.

Lastly:


rake deploy


This should pull everything down and place it in the "current" directory (in relation to cwd).

Create a link to mongrel_cluster script and mongrel_cluster.yml then add to startup:


mkdir /etc/mongrel_cluster
ln -s /home/build/deploy/current/config/mongrel_cluster.yml /etc/mongrel_cluster/railsapp.yml
ln -s /usr/lib/ruby/gems/1.8/gems/mongrel_cluster-0.1.3/resources/mongrel_cluster /etc/init.d/mongrel_cluster
chmod +x /etc/init.d/mongrel_cluster
rc-update /etc/init.d/mongrel_cluster default

TODO: autostart failing on Gentoo

Lastly, start the mongrels:


/etc/init.d/mongrel_cluster start


Test from port 80, 8000, 8001 and 8002 that the rails intro page comes up. Done.

No comments: