Chapter 13. Scheduling Maintenance tasks

From the LiveJournal user account (or whatever user is running LJ), you need to install some crontabs. These are periodic commands that run and manage your LiveJournal installation.

$ crontab -u lj -e

Note

This will bring up either your $EDITOR, or vi. If you want to set your editor explicitly, do:

$ EDITOR='nano -w' crontab -e

Now, enter the following stuff between the dotted lines below. Not all of it is necessary. See the comments below. The LJHOME= line is required. See the section above about how the $LJHOME environment variable is required everywhere. This is another place.

LJHOME=/home/lj
MAILTO=

# Essential:
* */12 * * * /home/lj/bin/ljmaint.pl clean_caches >/dev/null     1

# If you want statistics:
30 1 * * * /home/lj/bin/ljmaint.pl genstats genstats_size >/dev/null
5 2 * * 0 /home/lj/bin/ljmaint.pl genstats_weekly > /dev/null

# Various tasks
15 1 * * * /home/lj/bin/ljmaint.pl joinmail > /dev/null
30 * * * * /home/lj/bin/ljmaint.pl synsuck > /dev/null
5 2 * * 0 /home/lj/bin/ljmaint.pl memeclean > /dev/null
15 1 * * * /home/lj/bin/ljmaint.pl clean_spamreports > /dev/null

# Optional, if you want to use CAPTCHAs:
30 * * * * /home/lj/bin/ljmaint.pl gen_audio_captchas gen_image_captchas clean_captchas > /dev/null

# If you are running a high-load site with $LJ::CMDBUFFER on,
# there's another one to install:
*/5 * * * * /home/lj/bin/qbufferd.pl >/dev/null      2

1

Tip

You can set up your Linux system to record any errors, and standard output, running the above tasks.

            Change:    /dev/null
            To:        /var/log/cronrun.log 2>&1

2

If query-buffering is off, you can still run that, but it's not needed. Packagers should make their packages install it, since it doesn't hurt if it is running and not used. It'll die off right away if it realizes it's not needed. Otherwise it'll start up in the background and run every 15 seconds or so. Future startups by cron will only make sure it hasn't died (like if the database dies).

The cmdbuffer table and related functions are just the successor to querybuffer. It is a clustered version of the earlier tool, using specialized commands instead of general table locking. The qbufferd.pl tool uses the new commands.

The ljmaint.pl synsuck item above fetches new entries for syndicated feed accounts. If you include this, you should also disable event logging from your %LJ::DISABLED hash ('eventlogrecord' => 1,). An alternative method is using TheSchwartz workers to handle syndicated feeds. That is a replacement method, so you do not need the above cron job and %LJ::DISABLED key.