How to run Drupal cron maintenance tasks under Mosso hosting

Update: Mosso was rebranded as The Rackspace Cloud in June 2009.

Update 1 Jan 2010: It looks like Rackspace has fixed the problem with Mosso's Scheduled Tasks. Anonymous' comment tipped me off that you can now set the command language to http, then enter your site's cron.php as the command to run.


If you host a Drupal site on Mosso (now The Rackspace Cloud), there's a good chance that you're using Poor man's Cron to run the maintenance tasks. Poor man's Cron does a good job but it can cause problems, such as irregular cron job runs and extra load on your hosting environment. This guide will show you how to use Mosso's Scheduled Tasks to run Drupal's cron maintenance (cron.php) file.

Since Mosso's Scheduled Tasks control doesn't allow you to run system commands as you would with standard cron jobs, it's not immediately obvious how to apply the instructions in drupal.org's Beginner's guide for Cron. What you'll need to do is use it to kick-off a perl script that runs curl.

Setting up the Scheduled Task

1. First create a simple perl script with the following lines:

#!/usr/bin/perl -w
system ("curl --silent --compressed http://example.com/cron.php");

Remember to replace example.com with your site's domain. Save the script as cron.pl and set the execute bits on the file's permissions.

2. Upload the script to your Mosso Cloud Site. I put mine under a scripts directory above web/content:

/mnt/target05/123456/example.com/scripts/cron.pl

3. Login to your Mosso control panel, select your Cloud Site and click the Features tab. Click Add New Task under the Scheduled Tasks (Cron Jobs) section.

4. Enter your cron settings:

  • Status: set to ON
  • Task Name (Common Name): Give this task a name
  • Email Address for Output: enter noreply@mosso.com if you don't want to receive notifications about the task's execution result
  • Command Language: set to perl
  • Command to Run: set to scripts/cron.pl

5. Click Save Task. You should now have a cron job set to run Drupal's maintenance cron.php file at your specified intervals.

Testing the Scheduled Task

It's a good idea to test the Scheduled Task by entering your email address for the output and setting the frequency to repeat every 5 minutes. Wait for an email from Task Scheduler. If the task executed successfully, the body should look something like this:

This is an automatically created email, sent to inform you that your scheduled task has completed. Here are the results of the execution of your task:

Task Started at DayOfWeek Mon Day Time
--------------------------------------
Command to be executed is: /usr/bin/perl /mnt/Target00/123456/example.com/scripts/cron.pl
Task ID of this command is: 12345
Where should log be written: /mnt/Target00/123456/example.com/logs
Email address: user@example.com

--------------------------------------
Task ended at DayOfWeek Mon Day Time

If you have any questions please do not hesitate to contact us.

Website Support Team

Now log in to your Drupal site and view the page Administer > Logs > Status report. Check that the Last run time under Cron maintenance tasks roughly corresponds to your cron job set in the Mosso control panel.

Comments

Thanks

Thanks for the guide, saved me some time ;)

Great Post

Hi Anthony thank you for the excellent post, I had been trying to run the cron.php file from Mosso's scheduled tasks pane with no luck. Your post did the trick. Thanks again.

can we prevent "No suitable nodes..." messages on long processes

Thanks for this tip.

I have learned that the Control panel allows you to set http as one of the Command Languages, in then you can assign a URL (in this case http://domain.com/cron.php).

However, I have been monitoring it for the past 3 days and 2/3 times it outputs No Suitable Nodes are available..

My first suspect was that the MySQL connection was flakey because the logs indicated several "MySQL Server has gone away" errors.

However, I have since learned that this is happening because the "browser agent" that submitted the request to cron.php did no receive any output for 30-60 seconds and thus the load balance system is assuming that the "browser agent" has died somehow and thus kills the MySQL connection.

Any ideas on how to fix this? My first thought would be to somehow create a module that inserts a momentary "ping" back to the browser in the form of some kind of echo or print statement that will "keep alive" the browser connection while cron.php is processing (or any other long process for that matter)

I would really appreciate a push in the right direction and perhaps collaborate on creating a contrib module for other Mosso customers who have the same problems.... we would be heroes to alot of folks.

No Suitable Nodes

Rolando, did you ever find a solution to the "no suitable nodes" error message, I am still trying to find a solution, but haven't yet. I saw this blog post, but the suggested solution does not seem to work

http://1drupal.blogspot.com/2010/02/development-no-suitable-nodes-available.html

Great help

Just in case you can't read like me, Mosso's Scheduled Task appends the server address so in the example above you would need to set the path to to the web folder: web/content/scripts.cron.pl

How to run Drupal cron maintenance tasks under Mosso hosting

Thanks for the above information. I would like to know the true concept of hosting such as web hosting or website hosting etc.

Simpler solution?

I read this, and thought "There *has* to be a simpler way to run cron on a cloud hosting system that costs this much" :)

After chatting with Rackspace, it looks like you can just run cron for Drupal by going to the control panel for configuring cron jobs, switching the selector to "php" (it defaults to ruby) and giving it the full path to cron.php.

It'll add in the path from /mnt by default, so this means just entering "web/content/cron.php" in the form.

For anyone new to this, the "scheduled tasks" pane is under the "features" tab in the control panel.

New feature?

Thanks for the tip Dave. It's possible that your solution was a new feature rolled-out since I wrote this article. Previously it was not possible to simply give the path to cron.php. No matter what I tried, that just wouldn't work.

Perhaps this is something Rackspace fixed after acquiring Mosso. I will see if your solution works next time I need to set up a cron job. If anyone else can confirm this, feel free to post your comment here.

Doesn't work

I tried Dave's tip and can confirm it does not work. I'll use the work around in the post.

What does Work

I just wrote a first reply to this pointing out that Dave's solution doesn't work. What DOES work and is easy is set the command language to http, and the command to run as the full url of cron, so http://www.example.com/cron.php. That's it!

I get this..

When using Dave's suggestion of "php" cron for rackspace cloud, i get the following error in my e-mail:

PHP Warning: include_once(./includes/bootstrap.inc): failed to open stream: No such file or directory in /mnt/stor1-wc2-dfw1/#/aca.website.com/web/content/cron.php on line 9 PHP Warning: include_once(): Failed opening './includes/bootstrap.inc' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /mnt/stor1-wc2-dfw1/#/aca.website.com/web/content/cron.php on line 9 PHP Fatal error: Call to undefined function drupal_bootstrap() in /mnt/stor1-wc2-dfw1/#/aca.website.com/web/content/cron.php on line 10

Thanks for this. I couldn't

Thanks for this. I couldn't figure out how to stop receiving the email notifications - since it is a required field when creating Scheduled Tasks (Cron Jobs) in the control panel. Now I use noreply@mosso.com. Brilliant.

I can confirm that Rackspace Cloud Sites (Mosso) does now allow you to choose several languages to invoke a script on the server (php, perl, python, ruby). I still use the http: method, as it is dead simple.

Cheers.

I have a drupal based site.

I have a drupal based site. The front page is about 200kb and I have 10 trimmed topics in front page. Currently the site is hosted on a shared server. My question is how many hits or page loads per hour/minute should I have before it would be necessary to switch to a dedicated server?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.