Thursday, April 23rd, 2009 | Author:

Hey All,

So I have an account over at JaguarPC and I love it a lot there, they support everything I need and help me with all that I ask. However, there seems to be a snafu/caveat what have you to running RoR (Ruby on Rails) apps at JPC. cPanel runs RoRs apps using a mongrel instance, this is fine and it works….but sometimes it dies and needs to be restarted. Highly annoying….I run my redmine installation off of one of these mongrel instances and I really can’t have it be down. So….I devised this little gem below to check if your mongrel instance is down, if so to restart it.

To use the script throw it in your cPanel root and add the following line to your crontab:

*/5 * * * * php ~/reboot.php

Be sure to update the command above to reflect what you named the script…..

Hopefully someone else finds it useful and if you need help with the script comment!

cPanel Ror Mongrel Reboot

 * cPanel Mongrel Rebooter - v0.1
 * Author: Robert Navarro <[email protected]>

 * The siteCheck function has the following parameters
 * $url - This is the url of the application you want to check
 * $searchString - This is the erroneous string you want search the site for
 * $appPath - This is the full path to your cPanel RoR app installation
 * $appPort - This is the port that your cPanel RoR app runs on
 * You can find the application port by running:
 * # ps aux |grep mongrel |grep <your username>
siteCheck("http://<my redmine install>","502 Proxy Error","~/Sites/<my redmine install>/","12001");

function siteCheck($url,$searchString,$appPath,$appPort) {
 // open the remote URL for reading
 $fp = fopen($url, 'r') or die('Unable to open file '.$off_site.' for reading');

 $buffer = '';

 // read in chunks
 $buffer .= fgets($fp, 4096);

 // strip HTML but leave the tags you want
 $output = strip_tags($buffer,'<a>

 // convert all whitespace, tabs and newlines into one single whitespace
 $output = preg_replace('/\s+/', ' ', $output);

 if(strstr($output,$searchString)) {

function restart($path,$port) {
 exec("cd $path;mongrel_rails start -p $port -d -e production -P $path/log/");


Category: Development
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.