Some production maintenance tasks on Dreamhosted Rails app with crontab 2

Posted by Tim Connor Fri, 13 Apr 2007 17:48:00 GMT

crontab


MAILTO=me@mydomain.com
# minute (0-59),
# |      hour (0-23),
# |      |       day of the month (1-31),
# |      |       |       month of the year (1-12),
# |      |       |       |       day of the week
# |      |       |       |       |
  */5    *       *       *       *   wget -q -O /dev/null http://mydomain.com >/dev/null
  @hourly /home/myuser/clear_timocracy_sessions.sh
  @daily /home/myuser/rotate_timocracy_logs.sh
Grabs the site every 5 minutes to keep the fcgi alive on Dreamhost, and calls scripts that clear the sessions and rotate the logs h3. clear_timocracy_sessions.sh

#!/bin/bash
/home/mysuser/mydomain/script/runner -e production "CGI::Session::ActiveRecordStore::Session.destroy_all( ['updated_at <?', 1.day.ago])" 
Clears out sessions older than a day. h3. rotate_timocracy_logs.sh

#!/bin/bash
cd /home/myuser/mydomain
/usr/sbin/logrotate -s log/logrotate.status config/logrotate.conf -f; touch public/dispatch.fcgi
Calls logrotate and then updates the timestamp on dispatch.fcgi, so Apache will create new worker processes h3. config/logrotate.conf

"log/*.log" {
  compress
  weekly
  delaycompress
  missingok
  notifempty
  rotate 52
  create
}
Archive weekly, keeping a years worth of logs. delaycompress – wait to gzip them, till the next week, both for ease of reading the most recent and so there is time for the fcgi threads to get killed off, since they are pointing at the old log.
  1. Phil Verghese 6 months later:

    Thanks, this was very helpful! While searching for help on logrotate for Rails apps, I also found this posting that was useful.

    He suggests adding /var/www/your_app/script/process/reaper -a graceful -d /var/www/your_app/public/dispatch.fcgi 1>/dev/null 2>&1 || true

    as a postrotate action in your logrotate.conf to gracefully clean up the fcgi processes (and ensure they aren’t writing to the rotated log files).

  2. Tim Connor 6 months later:

    Thanks for the tip, Phil. On shared hosting you aren’t always able to reap your processes cleanly. On the ever troublesome Dreamhost, touching the dispatch.fcgi seems about the safest thing way to do it.

Comment form

(leave url/email »)

Help with Textile (code)