[Grok-dev] spotlight on: z3c.recipe.usercrontab

Jan-Wijbrand Kolman janwijbrand at gmail.com
Sun Jan 17 05:57:45 EST 2010


Spotlight on...

z3c.recipe.usercrontab[1] is a zc.buildout[2] recipe. With this recipe you can 
define crontab[2] 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[4], 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.

[1] http://pypi.python.org/pypi/z3c.recipe.usercrontab

[1] http://www.buildout.org/ and http://pypi.python.org/pypi/zc.buildout

[2] http://en.wikipedia.org/wiki/Cron

[3] for example with: http://pypi.python.org/pypi/tha.logcheck




More information about the Grok-dev mailing list