如何将cron作业部署到生产环境中? [英] How do you deploy cron jobs to production?

查看:135
本文介绍了如何将cron作业部署到生产环境中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们如何部署/版本控制cronjobs到生产?我更好奇的是人们使用的约定/标准比任何特定的解决方案,但我碰巧使用git进行版本控制,并且cronjob运行一个python / django脚本。

解决方案

如果您使用面料可以添加一个函数来编辑你的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(免责声明:完全未经测试,不是非常等幂)。


  1. 将crontab保存到临时文件。


  2. 将一行添加到tmp文件。


  3. 这可能不是你想要做的,但沿着这些线你可以考虑检查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).

    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.)

    这篇关于如何将cron作业部署到生产环境中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆