Cron Job Tips for Rails

Posted by Miraenda Sun, 04 Jun 2006 20:39:00 GMT

Sometimes, you need to chown or run a command for your Rails application, but you do not have shell access to do this on our shared servers. These are a couple of tips you can use to process the directives you need to run.

A. Where to setup crons:

  1. Log into cPanel.
  2. Click on Cron Jobs icon:
  3. Cron Jobs
  4. Click "Advanced (Unix Style)" button:
  5. Advanced (Unix Style) Button
  6. Set your email address to one you use (example shows mine, but don't input mine, input yours :)):
    Cron Job Email Address
  7. Input the cron with the following as an example image of what you might input:
  8. Cron Jobs Advanced Screen

  9. This would run the cron at 10 minutes after 7 (7:10am) Pacific time each day of the week (Day - * = every; Month - * = every; Weekday - * = every).
  10. For any cron you enter, ensure you put it at a time that is greater than every 15 minutes to avoid it being excessive on the system. Most the crons I go over below you would only need to run 1 time and then remove them.
  11. After you have filled out the cron, rember to click the "Commit changes" button, then click the Go Back link on the new screen:
  12. Go Back link

  13. After you receive an email to your account about the cron processing, delete the cron using the "Delete" link to the far right of it in the "Advanced (Unix Style)" area:
    Delete

B. Fixing ownership permissions:
* * * * * cd /home/user/ && chown -R user:user appname

This cron would fix the ownership on your Ruby folders if they are owned by root to where they would be reset to your username. Replace user with your cPanel username; replace appname with the folder for your Rails application.

As this cron would run every minute of every day, you simply need to let it run the once and look at the email output to your email address that it was successful, then you should delete this cron from cPanel's Cron Jobs area.

C. Running ./dispatch.fcgi to find out why a Rails application isn't working:
* * * * * cd /home/user/appname/public && ./dispatch.fcgi

This cron will run ./dispatch.fcgi to see why you might be receiving an error in a browser for your Rails application. As mentioned in Section B, remember to replace user with your cPanel username and to replace appname with the folder name for your Rails application.

Normal output for this cron would be the following when you receive the email in your email account for it:

Status: 500 Internal Server Error
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
 <h1>Application error (Apache)</h1>
 <p>Change this error message for exceptions thrown outside
 of an action (like in Dispatcher setups or broken Ruby code)
 in public/500.html</p>
</body>
</html>

Any other output for ./dispatch.fcgi are not normal and should be looked up using Google to resolve. You could also post on Lunarforums Ruby area for assistance.

Please remember to delete the cron after you successfully get the message to your email account for the cron.

Note that if you get any errors about not being able to log to development.log, fastcgi.crash.log or production.log, you need to chown those logs to your username. They are typically located at /home/user/appname/log/ location (again, where user is your cPanel username and appname is your Rails application folder name).

Posted in  | 2 comments | 30 trackbacks

Older posts: 1 ... 5 6 7 8 9 ... 11