Welcome Guest | Login

Ruby on Rails & Mongrel Hosting w/ HostingRails.com - Setup Instructions



This is a wiki article created by HostingRails users. Please login or signup to make edits.


The first thing you need to do is make sure your app is up and running with FastCGI -- follow this tutorial.

Then start up your mongrel instance or cluster and set your reboot crontab correctly:


-----------------------------
A Single Mongrel Instance
-----------------------------


If you wish to run a single Mongrel server for a Rails application (requires at least 50MB of dedicated memory on your account), then make note of the port that was assigned to you in your welcome email and start your mongrel instance
[~] cd yourapp
[~/yourapp] mongrel_rails start -e production -p 4*** -d  
  • The -e makes sure you're in production mode (HostingRails requires this on their servers)
  • The -p assigns your port (if you put something different than what was assigned to you then your app will
    not work)
  • The -d makes sure your instance will remain running in the background.  
Also, this is very important!!

If the server is rebooted you need to make sure your instance is restarted. Create a script restart-mon.sh somewhere in your home directory e.g. in a directory called script:
[~]# cd ~
[~]# mkdir script
[~]# cd script
[~]# vi restart-mon.sh
and enter the following content:
#!/bin/sh
cd /home/username/railsapp/log && rm mongrel.pid -f
pkill -9 mongrel_rails -u username
cd /home/username/railsapp && /usr/local/bin/mongrel_rails start -e production -p 4*** -d
...making sure you add your appropriate username/app/port info in there!!. In vi:
  • press I to enable enter mode
  • enter data
  • press ESC to leave enter mode
  • press :
  • press W, press Q to save and exit
Please also make sure the script is executable (chmod 744)!
Now open up your crontab:  
[~] crontab -e
and then enter the following:
# restart your mongrel server
@reboot /bin/sh /home/username/script/restart-mon.sh
...making sure you add your appropriate username and path to your restart-mon.sh script in there!!.

Press control-o to save and control-x to exit nano. If you get an message like "bad minute errors in crontab file, can't install..." try again and this time resize your ssh client window so there are no line-breaks.

And that's it, you should be good to go.

Now you need to notify support that you're ready to have your vhost proxy setup. (use MONGREL PROXY SETUP as the subject of your email, be sure to give them the following four items:

1) the URL of your working Fastcgi app so they can test it.  
2) the full path to your Rails app...i.e. /home/username/path/to/railsapp).  
3) the port you used
4) confirmation that your Mongrel process is up and running (check via ps in your shell) and that your reboot crontab is set with no typos or mistakes.  

Support will then change your entry in the httpd.conf file to proxy requests to your port and make sure your application is working - this will happen within 12 hours, usually much quicker.  

If you need to restart your mongrel instance to flush caching, do a
[~] cd yourapp
[~/yourapp] mongrel_rails restart  
or if that doesn't work:

[~] cd yourapp
[~/yourapp] mongrel_rails stop
 ...
[~/yourapp] mongrel_rails start -e production -p 4*** -d  
and if that doesn't work you may need to manually stop the mongrel process (type ps and note the process ID, second column number, of your mongrel_rails process) - issue a

[~] kill <your process id number> 
[~] cd yourapp
[~/yourapp] mongrel_rails start -e production -p 4*** -d
ALSO!! - if your website shows a 'Service Temporarily Unavailable' Error, then this means that your mongrel server is down and you need to get it back up



-------------------------
A Mongrel Cluster
-------------------------


If your account has 100MB or more of dedicated memory then make note of the port that was assigned to you in your welcome email and configure your mongrel_cluster.  Please first read what the process is like for a single mongrel server above, then you will essentially follow in with multiple Mongrels.  

[~] cd yourapp
[~/yourapp] mongrel_rails cluster::configure -e production -p 4***0 -N * -c /home/username/railsapp --user username --group username
Example for a cluster of 4:
[~] cd app
[~/app] mongrel_rails cluster::configure -e production -p 46370 -N 4 -c /home/cooluser/app --user cooluser --group cooluser
There are some important things in here to note:
     
  • Your port needs to have that appended "0".
  • The -N * denotes how many instances you will be running in your cluster.  * is 1,2,3,4,5,or 6, depending on how many instances you purchased.  
  • The -c makes sure the mongrel_cluster gem knows where to write the configuration file
ok - once your mongrel_cluster is configured then all you need to do is start it up.
[~/yourapp] mongrel_rails cluster::start
if you need to restart it to flush cached content or something, make sure to do a
[~/yourapp] mongrel_rails cluster::restart
or if that doesn't work:

[~/yourapp] mongrel_rails cluster::stop
 ...
[~/yourapp] mongrel_rails cluster::start
or if that doesn't work see above and you may need to clear things out like a single instance.  


Also, this is very important!!

If the server is rebooted you need to make sure your instance is restarted.  Open up your crontab:  
[~] crontab -e
and then enter the following:
#clear out pid files if they didn't get erased 
@reboot cd /home/username/railsapp/log && rm mongrel.4* -f

#reboot first instance (all one line)
@reboot cd /home/username/railsapp && /usr/local/bin/mongrel_rails start -e production -d -p 4***0 -P /home/username/railsapp/log/mongrel.4***0.pid

#reboot second instance (all one line)
@reboot cd /home/username/railsapp && /usr/local/bin/mongrel_rails start -e production -d -p 4***1 -P /home/username/railsapp/log/mongrel.4***1.pid

#reboot more instances in a similar manner
Be sure to triple-check that you get this file correct.  Make sure your username, railsapp, and port (4***) are plugged in correctly.  Note that the final digit of the port will increase 0,1,2,3,etc...


And that's it,

Now you need to notify support that you're ready to have your vhost proxy load balancer setup. (use MONGREL PROXY LOAD BALANCER SETUP as the subject of your email, be sure to give them:

1) the URL of your working Fastcgi app so they can test it.  
2) the full path to your Rails app...i.e. /home/username/path/to/railsapp).  
3) confirmation that your Mongrel processes are up and running (check via ps in your shell) and that your reboot crontab is set with no typos or mistakes.  
4) the ports you used

They will then change your entry in the httpd.conf file to proxy and load balance requests to your ports and make sure your application is working - this will happen within 12 hours, usually much quicker.  

ALSO!! - if your website shows a 'Service Temporarily Unavailable' Error, then this means that your mongrel cluster is down and you need to get it back up. :)" " " "



Hello Guest! In order to edit this article you must be an active client with us, please log in or sign up today!






Contributing Author(s):
Jillian
Brian
William
Borogoves
Banjerluke
Rshannon
Damartman
Mackerr
Shoreside