Vote Charlie!

Setting up Movable Type publishing queue and logging

Posted at age 25.

Movable Type templates can be published in many ways, including “static” publishing upon each entry save, “manual” publishing only when an administrator triggers them, or in the background using the “Publishing Queue“. This last option takes some additional setup, but is well worth it.

If you are running MT on a Linux distribution, you can use the following steps to set up MT’s “run-periodic-tasks” script that processes jobs in the publishing queue.

Determining MT’s server user

First, you’ll need to determine the user Movable Type runs under, which is usually the user your web server software is configured to run as. You can check your Apache, Nginx or other server configuration files for the file, but it might be easiest to just check a file generated by MT by using a command like:

$ ls -al /var/www | grep index
-rw-r--r--  1 www-data www-data   22791 Aug 10 06:11 index.html

This uses the ls command to produce a detailed list of files in /var/www and filter the result to only show lines containing “index”. We see in the output the index.html file is owned by the user www-data:www-data.

Preparing the log

You can skip this step if desired, but then you’ll need to omit -verbose >> /var/log/movabletype/rpt.log 2>&1 from the command you will add to your crontab.

We will create a folder to store output from the RPT script and assign it appropriate permissions. You may or may not need the sudo, depending on whether you are logged on as a super user.

sudo mkdir /var/log/movabletype
sudo chown -R www-data:www-data /var/log/movabletype

Next we will configure logrotate to rotate the MT logs this will create. Create a the file /etc/logrotate.d/movabletype-rpt and add to it:

/var/log/movabletype/rpt.log {
    rotate 30

You might create this file using vim by running the command sudo vim /etc/logrotate.d/movabletype-rpt, typing I to enter insert mode, pasting the text, hitting ESC to enter command mode, typing :x and hitting enter.

Scheduling RPT to run

You should execute the “run-periodic-tasks” script as the user MT runs under, as determined above. Edit the crontab for that user:

crontab -e -uwww-data

Add this line:

*/3 * * * * cd /usr/lib/cgi-bin/mt; perl ./tools/run-periodic-tasks -verbose >> /var/log/movabletype/rpt.log 2>&1

Replace /usr/lib/cgi-bin/mtwith the path to your MT installation, and configure the first part of the line to whatever frequency you desire. As written, cron will execute the command every three minutes.

Preventing RPT from overloading server

At this point, RPT will execute over and over, and you might end up with many instances running at once if there are many jobs in the publishing queue. To limit the number of RPT processes that can run at once, add the following line to your mt-config.cgi file:

RPTProcessCap 3

You can use any number you wish, but three should work well.

Managing the publishing queue

If you would like to be able to see what jobs are in the publishing queue and have the option to delete jobs or change the priority of jobs, install Publish Queue Manager plugin for Movable Type.