Setting up run-periodic-tasks
The run-periodic-tasks
script can be run from the command line, put into a crontab as a recurring task, or run in daemon mode. The script will also log to stdout and stderr.
The script accepts the following arguments when run:
--daemon
Using this flag signals to run-periodic-tasks to run itself as a daemon process in the background. In the mode, run-periodic-tasks will never exit and run continuously waiting for work to be done.
--sleep <seconds>
Takes as input an integer which indicates the number of seconds to wait before checking for new jobs. This option is only valid when running in daemon mode, and if no value is provided the system defaults to 5.
--load <jobs>
Takes as input an integer which indicates the number of jobs to process at one time. This option is only valid when running in daemon mode. The default is 10.
--verbose
A flag which tells the script to log in verbose mode.
--randomly
When processing a batch of jobs (which are drawn in priority order), items within that batch may be randomly executed in order to reduce contention between multiple daemons working on the job queue. This option is only recommended when multiple daemons are running. This option is new to MT version 4.2.
--leak
This option is for developers to use to detect Perl objects that are not reclaimed properly while tasks are being run. This option should be used in conjunction with the verbose
flag and works best when running the script in daemon mode. This option requires the installation of the Devel::Leak::Object
CPAN module. This option is new to MT version 4.2.
Example - Launching a Daemon Process
The following command tells the script to run as a daemon, log verbosely and output log items.
cd /path/to/mt; perl ./tools/run-periodic-tasks -daemon -verbose >> /var/log/httpd/mt.log &
Alternatively, you can instruct the script silently, like so:
cd /path/to/mt; perl ./tools/run-periodic-tasks -daemon &
Example - Executing from Cron
The following crontab entry will execute run-periodic-tasks
once every 10 minutes.
0,10,20,30,40,50 * * * * cd /path/to/mt; perl ./tools/run-periodic-tasks -verbose >> /var/log/httpd/mt.log
How to Setup Cron in Unix
Warning, the following instructions assume you have some familiarity with the Unix command line.
To setup run-periodic-tasks
to run via cron, execute the following commands. First, edit your “crontab:”
prompt> crontab -e
This will open your crontab in your text editor of choice. On a new line in this file, add the following text (changing /path/to/mt accordingly):
0,10,20,30,40,50 * * * * cd /path/to/mt; perl ./tools/run-periodic-tasks
Then save the file and quit your text editor. This will install the new command into your crontab, which will be executed every 10 minutes starting at the top of the hour.
That’s it.
Gautam Patel on August 3, 2009, 3:45 a.m. Reply
Using a regular CPanel interface, it’s sometimes easier to go to Cron, then select advanced and set this in the command line:
And then set the frequency in the boxes on the left. (*/10 * * * * will run every ten minutes)
Zeus on April 2, 2010, 1:10 a.m. Reply
I got this error:
Can’t locate MT/TheSchwartz.pm in @INC (@INC contains: lib ../lib extlib ../extlib …..
I could fix it by changing the run-periodic-tasks script at line 11 where the include folders have relative path, I changed them to real path and it just worked.
Matthew Miller on April 14, 2011, 7:13 p.m. Reply
I was using:
but it always produced an empty file. After reading this thread on the Ubuntu forums, I switched it to this:
and it works!