Personal tools
You are here: Home Blog Spotlight on: z3c.recipe.usercrontab

Spotlight on: z3c.recipe.usercrontab

z3c.recipe.usercrontab is a zc.buildout recipe. With this recipe you can define crontab rules that will be installed in the user's crontab. Written by Jan-Wijbrand Kolman.

z3c.recipe.usercrontab is a zc.buildout recipe. With this recipe you can define crontab rules that will be installed in the user's crontab. As such it is probably only useful on unix-like systems. It has been tested on Linux and Mac OS X.

With this recipe it is easy to define recurring actions related to the deployment of your application. Examples are: periodically checking the event log file for irregularities, sending emails from a mail queue, or have cron start your application after a system reboot.

The usercrontab part in your buildout.cfg file could look like this:

[buildout]
...
parts = ...
        logcheck
        reboot

[logcheck]
recipe = z3c.recipe.usercrontab
times = 39 * * * *
command = [cmd]

[reboot]
recipe = z3c.recipe.usercrontab
times = @reboot
command = ${buildout:directory}/bin/zopectl start

After running ./bin/buildout you can inspect the result of the recipe with:

$ crontab -l

There you will see something like:

# Generated by /home/jw/projects/sandbox/usercrontab [logcheck]
39 * * * *    /home/jw/projects/sandbox/usercrontab/bin/[cmd]
# END /home/jw/projects/sandbox/usercrontab [logcheck]

# Generated by /home/jw/projects/sandbox/usercrontab [reboot]
@reboot       /home/jw/projects/sandbox/usercrontab/bin/zopectl start
# END /home/jw/projects/sandbox/usercrontab [reboot]

The markers around the actual crontab line are important: z3c.recipe.usercrontab will use this markers to see if the buildout part already did its work in order to prevent duplicates. The markers are also used to remove these lines from the crontab, when uninstalling the part.

The Python Package Index page for z3c.recipe.usercrontab explain the use of the times and command directives in more detail.