我遇到了在Elastic Beanstalk上设置简单的cron任务的问题 . 我发现其他一些问题在这里很有用,但我仍然无法让cron执行 . 我不确定它是否是AWS问题,或者脚本本身是否正在执行 . 该脚本在YII中设置为控制台命令 . 我没有发现任何PHP错误,并且加载了ec2实例而没有错误 . 这是我到目前为止所做的:

我在应用程序的根目录上创建了一个名为.ebextensions的文件夹 .

在该文件夹中,我创建了一个包含内容的配置文件

# Installing dos2unix in case files are edited on windows PC
 packages:
     yum:
        dos2unix: []
 container_commands:
     01-command:
        command:         dos2unix -k cron_setup.sh

     02-command:
        command:         chmod 700 cron_setup.sh

     03-command:
         command:        "cat .ebextensions/cron_task.txt > /etc/cron.d/cron_task && chmod 644 /etc/cron.d/cron_task"
         # leader_only prevents problems when EB auto-scales
         leader_only:    true

文件cron_task.txt存在于带有内容的.ebextensions文件夹中

# The newline at the end of this file is extremely important.  Cron won't run without it.
* * * * *  /bin/php /var/www/html/crons.php test  > /dev/null

Crons.php是包含Yii框架的应用程序根目录下的文件

defined('YII_DEBUG') or define('YII_DEBUG',true);

// including Yii
require_once(dirname(__FILE__).$yii.'/yii.php');

// we'll use a separate config file
$configFile=dirname(__FILE__).'/protected/config/cron.php';

// creating and running console application
Yii::createConsoleApplication($configFile)->run();

config / cron.php文件是框架的安装文件,包括数据库连接和模型包含等

并且在cron_task.txt文件中引用的cron脚本是一个如下所示的控制台命令

class TestCommand extends CConsoleCommand {
    public function run($args) {
        $message = new Crontasks();
        $message->timestamp = date("Y-m-d H:i:s");
        $message->message = "test";
        $message->insert();
    }
}

在这里,我只是想在数据库中获取记录,以证明cron已成功执行 . 我似乎无法添加记录 .

问题是,我不知道这在哪里失败了 . 我没有收到任何实例错误 . 我拍了快照日志,似乎也找不到任何相关的错误 . 这里应该记录php错误吗?或者我是否必须自己设置以记录错误?问题是,我也无法通过SSH进入ec2 . 我收到权限被拒绝(公钥)错误!!即使我已经设置了安全组/密钥对并为实例使用了正确的公共DNS!

如果有人能看到任何明显的东西,我在这里做错了,请告诉我!否则,您是否可以提供任何建议,以查找可能阻止此cron任务执行的任何错误?非常感谢!!