Part 2: Setting up Nginx with a Mongrel cluster

Posted by Michael

In part one of setting up Nginx with a Mongrel cluster we set up the appropriate Nginx directories and configured our nginx.conf file.

Now that we have created our directories and we have our nginx.conf file sorted, let's get Nginx fired up using the configuration file we made.

nginx -c /home/username/nginx/nginx.conf

In most cases that command should fire up Nginx with the correct configuration for your Mongrels. If not and for reference, I have included some very handy commands to help you start, stop and kill Nginx.

## To kill Nginx
killall -u $USER -v -i nginx

## To start Nginx back up
nginx -c /home/username/nginx/nginx.conf

## Find the master Nginx process
ps -aef | egrep '(PID|nginx)'

## To kill the identified process
kill -15 'process-id'

Getting Mongrel cluster installed and configured

Assuming you have Rubygems already installed, we will go ahead and get Mongrel and Mongrel cluster via the 'gem' command. We will also drop the documentation when installing so we can save some system resources.

gem install mongrel mongrel_cluster --no-rdoc --no-ri

Now we need to create a mongrel_cluster.yml file that will live in our rails application. This file needs to go in the following directory:

myRailsApp/config/mongrel_cluster.yml

Your mongrel_cluster.yml will look similar to what I use. I say similar because what I use is a very simple 'bare bones' configuration. This works great for me, but you may find you need to alter the configuration to suit your requirements. Please note that 'myRailsApp' == 'mywebsite.com', it's the same directory. You can give them the same name, I do. But in this article I have used more descriptive naming.

1
2
3
4
5
6
7
8
9
10

---
port: '8000'
cwd: /home/username/myRailsApp
log_file: log/mongrel.log
environment: production
address: 127.0.0.1
pid_file: tmp/pids/mongrel.pid
servers: 3
docroot: public

Now we are ready to start our Mongrel cluster and hopefully they fire up. You will want to issue the following command as root user and from the root of your Rails application directory.

mongrel_rails cluster::start

So what happened? If you see the ports starting - well done!

starting port 8000
starting port 8001

Let's get the status of our Mongrel's

mongrel_rails cluster::status

You should hopefully get something similar to:

found pid_file: tmp/pids/mongrel.9000.pid
found mongrel_rails: port 8000, pid 2540

found pid_file: tmp/pids/mongrel.9001.pid
found mongrel_rails: port 8001, pid 2543

If you have issue's with stale PID files, just remove them and restart your Mongrel's.

cd tmp/pids
rm mongrel*

If you are still having trouble with missing Mongrel PID files, you might want to manually kill off each Mongrel process and then try to start your Mongrel cluster again.

## Find the Mongrel process/s
top
## Then hit
shift m

Look for the process number, now we will kill it or them.

kill -15 'process-id'

Now try starting up your Mongrel's. Good luck!

Comments

Leave a response