I have a bunch of projects that I push to a server with git and fab. They're a load of Django sites. Some of these sites have cron jobs.
I would like to be in a situation where I can:
Manage the site's cron jobs by editing a file locally and running a fab command (eg fab save deploy
as I currently do)
Have new jobs get installed remotely (only) and replace any old jobs (I don't want clone jobs each time)
Keep the same highly customisable time settings. Not all my issues can be solved by @hourly.
What's the best way to approach this?
I am aware of How do you deploy cron jobs to production? but the focus there seems to be about hacking the cronning into the fabric script and (at least in the answers) there's no consideration that there might be more than one project that needs cron jobs per user.
I'm after something that is stored in the VCS (I don't push my fabfile to git - and it's shared between all my projects) that will work alongside other jobs in crontab. It's no good if ProjectA and ProjectB overwrite each other's jobs each time I deploy.
It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week . 0 1 * * * - this means the cron will run always at 1 o'clock. * 1 * * * - this means the cron will run each minute when the hour is 1.
Anacron. Anacron is a periodic command scheduler just like cron. The only difference is that it does not need your computer to be always running. You can schedule your task to run at any time.
I'm not a fan of editing the crontab or per-user cron jobs; anyone editing the crontab
can mess up your deployment. Instead, I create scripts that go into /etc/cron.$interval
which allows me to deploy them with Puppet (see the cron type) or a simple cp
command.
So if I need a script that runs once per day, I either put that into $project/cron/cron.daily/$project
if I install without Puppet.
Alternatively, if you really need to merge crontabs, you should add a header and footer to each script, so it's easy to see where some part of the crontab comes from. The header/footer also allows you do automatically add/remove each script.
You should never replace the whole crontab because one day, someone will manually edit it. The edit will work until you deploy again at which time it will suddenly fail silently.
So here's my best idea so far:
/web/project_name/
/web/project_name/cron
On deploy, fab runs the following on the server:
find /web/ -maxdepth 2 -name cron | xargs cat | crontab
This munges any cron files it finds in /web/
and stuffs them in the crontab for my user. Better yet, if I have project independent jobs I want running, I can stick them in /web/cron
and they'll go at the top of the resulting crontab.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With