简体   繁体   English

实施时间表/ cron的正确方法

[英]Right way to implement schedule / cron

I need to add bulk objects creation in Pimcore. 我需要在Pimcore中添加批量对象的创建。 First I tried with web, but due to big size of set, Request taken long time and approach discarded in practical terms. 首先,我尝试使用Web,但是由于集合数量庞大,请求花了很长时间,并且实际上放弃了方法。

Then I chosen cron for schedule the jobs for later period, But I get other issue. 然后我选择了cron来安排以后的工作,但是我遇到了其他问题。 Like some other RAD application pimcore generate some of code automatically in some folders like /website/var/versions. 像其他RAD应用程序一样,pimcore在/ website / var / versions等文件夹中自动生成一些代码。 So these folder automatically get permission of web user ( in my case apache user ). 因此,这些文件夹会自动获得Web用户(在我的情况下为apache用户)的许可。

But My cron script run by normal user which execute Pimcore API calls for object/data creation but unable to write in folders due to insufficient permissions. 但是,由执行Pimcore API的普通用户运行的My cron脚本要求创建对象/数据,但由于权限不足而无法写入文件夹。 Now I can have one of two options. 现在,我可以选择以下两种方法之一。

  1. Run cron through apache user, which is big no for security reasons. 通过apache用户运行cron,出于安全原因,这是不行的。
  2. Give writable permissions ( chmod 777 like or add my user to apache group by using chown ). 授予可写权限(chmod 777或通过使用chown将我的用户添加到apache组)。 But pimcore create new folders time by time when managed from browser. 但是,当从浏览器进行管理时,pimcore会不时创建新文件夹。 So these new folders do not have permissions to write by cron script ( permission is max 755, I get for new folders which is not enough for group write ). 因此,这些新文件夹没有使用cron脚本编写的权限(权限最大为755,我得到的新文件夹不足以进行组写入)。

I searched previously on google and found command setfacl for setup default user / permissions for a folder. 我以前在google上搜索过,发现命令setfacl设置了文件夹的默认用户/权限。 Which I used like this. 我这样使用。

    `sudo setfacl -Rm u:apache:rwx,d:u:apache:rwx website/var/versions/object` 

But it regular failed and I need to give manually permission again and again. 但是它经常失败,我需要一次又一次地手动授予权限。

Now if any practical approach for fixing this ? 现在是否有解决此问题的实用方法?

Note : I am currently using Amazon Linux AMI. 注意:我当前正在使用Amazon Linux AMI。 But it can be later change to redhat or ubuntu, So Its better is a universal linux solution is available. 但是以后可以将其更改为redhat或ubuntu,因此更好的是可以使用通用Linux解决方案。

Pimcore already requires that its maintenance jobs (cron) are run under apache user, so not running your job under apache user might not improve things much. Pimcore已经要求其维护作业(cron)在apache用户下运行,因此不在apache用户下运行您的工作可能不会有多大改善。

But you might want to go with the approach that is used for the integrated newsletter sending. 但是,您可能希望采用用于集成新闻通讯发送的方法。

See /pimcore/modules/reports/controllers/NewsletterController.php:194 : 参见/pimcore/modules/reports/controllers/NewsletterController.php:194

$cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "send-newsletter.php"). " " . escapeshellarg($letter->getName()) . " " . escapeshellarg(Tool::getHostUrl());
            Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . "/newsletter--" . $letter->getName() . ".log");

Above code runs the CLI script /pimcore/cli/send-newsletter.php 上面的代码运行CLI脚本/pimcore/cli/send-newsletter.php

With this approach the cron is not needed and since the job is run as CLI it won't timeout (if you didn't explicitly set the timeout for PHP CLI). 使用这种方法,就不需要cron了,因为该作业是作为CLI运行的,所以它不会超时(如果您没有为PHP CLI显式设置超时)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM