如何将cron作业部署到生产中? [英] How do you deploy cron jobs to production?
问题描述
如果您使用 Fabric 进行破坏,您可以添加一个编辑你的crontab的函数。
def add_cronjob():
run('crontab -l> / tmp / crondump')
run('echo@daily /path/to/dostuff.sh 2> / dev / null>> / tmp / crondump')
run('crontab / tmp / crondump')
这将附加一个工作到你的crontab(免责声明:完全未经测试,不是非常幂等)。
-
将crontab保存到临时文件。
-
在tmp文件中附加一行。
-
将crontab写回来。
这完全不是你想要做的,但是沿着这些方向,你可以考虑将crontab检查为git,并在每次部署的服务器上覆盖它。 (如果您的项目有专用的用户)。
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.
If you are using Fabric for deploment you could add a function that edits your crontab.
def add_cronjob():
run('crontab -l > /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).
Save the crontab to a tempfile.
Append a line to the tmpfile.
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.)
这篇关于如何将cron作业部署到生产中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!