Monday, July 2, 2007

Start Mongrel Cluster on Boot - ubuntu fiesty

I have been following the steps here:
http://rails.aizatto.com/2007/05/20/deploying-ruby-on-rails-on-ubuntu-feisty-fawn-via-mongrel-cluster-and-apache/

I did the "Start Mongrel Cluster on Boot" section slightly differently.

first create a script for init.d (and make it runnable ie chmod +x your_script_name)

#!/usr/bin/env ruby
#
# app_name This is a startup script for use in /etc/init.d
#
# chkconfig: 2345 80 20
# description: Description of program / service

APP_START = '/var/www/railsapp.com/startme'

APP_STOP = '/var/www/railsapp.com/stopme'

case ARGV.first
when 'start':
exec APP_START
when 'stop':
exec APP_STOP
when 'restart':
#TODO
end

unless %w{start stop restart status}.include? ARGV.first
puts "Usage: #{APP_START} {start|stop|restart}"
exit
end

2) Then create the "startme" script in your rails app directory
(You can uncomment the cluster::configure for the first run)
(and make it runnable ie chmod +x your_script_name)

#!/bin/bash
#sudo mongrel_rails cluster::configure -e production -p 8000 -N 6 -c /var/www/railsapp.com -a 127.0.0.1 -l /var/www/railsapp.com/log/mongrel.log
mongrel_rails cluster::start -C /var/www/railsapp.com/config/mongrel_cluster.yml

3) Add start line in /etc/rc.local file
(Assuming you called your script "mongrel_processes")
/etc/init.d/mongrel_processes start

before the
exit 0

4) That should be it , start the script from init.d, if it works, well . . .

I find this version slightly easier to read and maintain.

Peter

2 comments:

addame said...

Hi!
Thanks a lot for this very instructive tutorial ! it helps me to get my small application up !

The only problem is when I tried to lunch mongrel_cluster, where I have problem.
In fact the mongrel_rails start -e production is working fine. However mongrel_rails cluster::start is not working. The log I get the following output :

starting port 8000
starting port 8001
starting port 8002

But when I lunched the browser to the application url and port 8000 for
example, the mongrels seems not working.

I looked at the log file and get for the first mongrel instance :

** Daemonized, any open files are closed. Look at tmp/mongrel.8000.pid
and log/mongrel.8000.log for info.
** Starting Mongrel listening at 0.0.0.0:8000
** Changing group to mongrel.
** Changing user to mongrel.
** Starting Rails with production environment...
** Mounting Rails at /home/rails/projects/myapps...
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:30:in
`gem_original_require': no such file to load --
/home/rails/projects/jokes/config/environment (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:30:in
`require'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:157:in
`rails'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:116:in
`cloaker_'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:138:in
`call'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:138:in
`listener'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:98:in
`cloaker_'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:51:in
`call'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:51:in
`initialize'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:83:in `new'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:83:in `run'
from
/usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in
`run'
from /usr/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:248
from /usr/bin/mongrel_rails:16:in `load'
from /usr/bin/mongrel_rails:16

It's the same thing for the two other instances.

My mongrel cluster configuration is as follows :

user: mongrel
group: mongrel
cwd: /home/rails/projects/myapps
log_file: log/mongrel.log
port: "8000"
environment: production
address: 127.0.0.1
pid_file: tmp/mongrel.pid
servers: 3



Do you have any idea of this problem ?

Thanks in advance !!

Addam

Peter Retief said...

Hi Addamme

I am totally sure what the problem could be but I would try run a cluster config script and then run the cluster::start - and obviously use your own app path directory for -c

here is what i used

sudo mongrel_rails cluster::configure -e production -p 8000 -N 3 -c /var/www/railsapp.com -a 127.0.0.1 -l

good luck :)

Peter