由于权限问题,django-chronograph 脚本不会从 cron 作业运行或手动运行

发布于 2024-12-04 15:25:06 字数 718 浏览 1 评论 0原文

我在通常的位置创建了一个自定义管理命令作为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

腻橙味 2024-12-11 15:25:06

答案是 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.

缪败 2024-12-11 15:25:06

您可能会发现这对于解决文件权限问题非常有用。 文件权限基础知识

您是否尝试过以适当的用户/服务身份运行 cron 作业?

要编辑其他 Linux 用户的 crontab 条目,请登录 root 并使用 -u {username} -e ,如下所示。

root@dev-db# crontab -u otheruser -e
@monthly /home/otheruser/fedora/bin/monthly-backup
00 09-18 * * * /home/otheruser/ubuntu/bin/check-db-status

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.

root@dev-db# crontab -u otheruser -e
@monthly /home/otheruser/fedora/bin/monthly-backup
00 09-18 * * * /home/otheruser/ubuntu/bin/check-db-status
闻呓 2024-12-11 15:25:06

当您使用虚拟环境时:
其中包括一个名为 chronograph.sh 的脚本。复制此文件
到您的项目目录。

cp chronograph.sh ~/virtualenvs/webbricks/chronograph.sh

您需要打开此脚本并修改虚拟环境的 activate 路径
script::

$PROJECT_PATH"/home/shofty/virtualenvs/webbricks/bin/activate"

确保此文件可执行,然后更新您的 crontab 以执行
脚本。

chmod a-x chronograph.sh

然后:
crontab -e

* * * * * /home/shofty/virtualenvs/webbricks/chronograph.sh /home/shofty/virtualenvs/webbricks/website

确保将 /path/to/your/project 作为第一个参数传递给脚本。
这应该确保 cron 在查找您的项目目录时不会出现问题。

As you're using a virtual environment:
Included is a script called chronograph.sh. Copy this file
to your project directory.

cp chronograph.sh ~/virtualenvs/webbricks/chronograph.sh

You need to open up this script and modify the path to your virtual environment's activate
script::

$PROJECT_PATH"/home/shofty/virtualenvs/webbricks/bin/activate"

Make sure that this file is executable and then update your crontab to execute the
script.

chmod a-x chronograph.sh

Then:
crontab -e

* * * * * /home/shofty/virtualenvs/webbricks/chronograph.sh /home/shofty/virtualenvs/webbricks/website

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.

記柔刀 2024-12-11 15:25:06

是操作系统权限被拒绝还是您收到了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文