由于权限问题,django-chronograph 脚本不会从 cron 作业运行或手动运行
我在通常的位置创建了一个自定义管理命令作为 py 文件。
计时码表安装在正确的位置并且同步正常。
我已经创建了 cron 作业,如下所示,
* * * * * /home/shofty/virtualenvs/webbricks/bin/chronograph -e /home/shofty/virtualenvs/webbricks/bin/activate_this.py -p /home/shofty/virtualenvs/webbricks/website
我也尝试了以下操作,因为我认为它可能是正确的,但不是文档中的内容,
* * * * * /home/shofty/virtualenvs/webbricks/bin/chronograph -e /home/shofty/virtualenvs/webbricks/bin/activate_this.py -p /home/shofty/virtualenvs/webbricks/website/manage.py cron
我添加了 manage.py cron 因为它是您运行来告诉计时功能查看的内容对于需要运行的作业。如果我在我的虚拟环境中并且我运行manage.py cron,它就会工作并且作业会运行。
这两个作业都无法运行,但是当我尝试以 su 或我的用户身份手动运行它们时,它们由于权限被拒绝而失败。不确定他们指的是什么许可。有人以前遇到过这个吗?
I've created a custom management command as a py file, in the usual place.
chronograph is installed in the right place and syncd ok.
I've created the cron job as the following
* * * * * /home/shofty/virtualenvs/webbricks/bin/chronograph -e /home/shofty/virtualenvs/webbricks/bin/activate_this.py -p /home/shofty/virtualenvs/webbricks/website
ive also tried the following, as i think it may be correct but not whats in the documentation
* * * * * /home/shofty/virtualenvs/webbricks/bin/chronograph -e /home/shofty/virtualenvs/webbricks/bin/activate_this.py -p /home/shofty/virtualenvs/webbricks/website/manage.py cron
I've added the manage.py cron because its what you run to tell the chronograph function to look for jobs that need running. if im in my virtual env and i run manage.py cron it works and the job runs.
both jobs are failing to run, but when i try to run them manually, as su or my user, they fail due to permissions denied. not sure what permission they're referring to. anyone come across this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
答案是 chronograph.sh 已被 chronograph 取代。尽管据说能够激活环境,但它并没有尽早导入 argparse,据我所知,argparse 不是内置于 python 2.5 中的,而是内置于 python 2.6 中的。然后就是为计时脚本找到正确的参数组合,作为参考的是 -p 和 -e,但不是 -s。
我还必须以 root 身份运行脚本,但将脚本定位在用户 virtualenv 内。
最后,我还必须将包目录的站点路径添加到计时脚本中,因为在我这样做之前它找不到 argparse。
The answer for this was that chronograph.sh has been superseded by chronograph. despite this supposedly being able to activate an env, it wasn't doing it early enough to import argparse which as far as i can tell isn't inbuilt to python 2.5 but is in 2.6. then its just down to getting the right combination of arguements for the chronograph script, which for reference is a -p and an -e but not an -s.
also i had to run the script as root but targetting the script inside the users virtualenv.
finally i also had to add site paths for packages directory to the chronograph script as it couldnt find argparse until i did that.
您可能会发现这对于解决文件权限问题非常有用。 文件权限基础知识
您是否尝试过以适当的用户/服务身份运行 cron 作业?
要编辑其他 Linux 用户的 crontab 条目,请登录 root 并使用 -u {username} -e ,如下所示。
You may find this comes in handy for issue you have with file permissions. File permission basics
Have you tried running the cron job as the appropriate user/service?
To edit crontab entries of other Linux users, login to root and use -u {username} -e as shown below.
当您使用虚拟环境时:
其中包括一个名为
chronograph.sh
的脚本。复制此文件到您的项目目录。
您需要打开此脚本并修改虚拟环境的
activate
路径script::
确保此文件可执行,然后更新您的
crontab
以执行脚本。
然后:
crontab -e
确保将
/path/to/your/project
作为第一个参数传递给脚本。这应该确保
cron
在查找您的项目目录时不会出现问题。As you're using a virtual environment:
Included is a script called
chronograph.sh
. Copy this fileto your project directory.
You need to open up this script and modify the path to your virtual environment's
activate
script::
Make sure that this file is executable and then update your
crontab
to execute thescript.
Then:
crontab -e
Make sure that you pass
/path/to/your/project
to the script as the first argument.This should ensure that
cron
shouldn't have problems finding your project directory.是操作系统权限被拒绝还是您收到了 403?如果是 403 我认为很可能是由 Django 的 CSRF 保护引起的。如果您的脚本发布到特定视图,请确保将其标记为 csrf_exempt
如果权限被拒绝是在文件系统/操作系统级别,那么我真的不知道。
Is it os permission denied or are your receiving a 403? If it is a 403 I think is most likely caused by Django's CSRF protection. If your script is posting to a particular view, make sure to mark it as csrf_exempt
If the permission denied is at the file system / operating system level then I don't really know.