views:

272

answers:

3

How do people deploy/version control cronjobs to production? I'm more curious about conventions/standards people use than any particular solution, but I happen to be using git for revision control, and the cronjob is running a python/django script.

+3  A: 

If you're using Fabric for deploment you could add a function that edits your crontab.

def add_cronjob():
    run('crontab > /tmp/crondump')
    run('echo "@daily /path/to/dostuff.sh 2>/dev/null" >> /tmp/crondump')
    run('crontab /tmp/crondump')

This would append a job to your crontab (disclaimer: totally untested and not very idempotent). (1. Save the crontab to a tempfile. 2. append a line to the tmpfile. 3.write the crontab back.)

This is propably not exactly what you want to do but along those lines you could think about checking the crontab into git and overwrite it on the server with every deploy. (if there's a dedicated user for your project.)

kioopi
A: 

You can probably use something like CFEngine/Chef for deployment (it can deploy everything - including cron jobs)

However, if you ask this question - it could be that you have many production servers each running large number of scheduled jobs. If this is the case, you probably want a tool that can not only deploy jobs, but also track success failure, allow you to easily look at logs from the last run, run statistics, allow you to easily change the schedule for many jobs and servers at once (due to planned maintenance...) etc.

I use a commercial tool called "UC4". I don't really recommend it, so I hope you can find a better program that can solve the same problem. I'm just saying that administration of jobs doesn't end when you deploy them.

+1  A: 

If you're using Django, take a look at the jobs system from django-command-extensions.

The benefits are that you can keep your jobs inside your project structure, with version control, write everything in Python and configure crontab only once.

hcalves