I am deploying my Laravel application to ElasticBeanstalk environment. I am trying to run a command in the Scheduling Task on the server. But it is not working. This is what I have done.
I schedule my command in the Kernel.php file as follow.
$schedule->command('counter:update')->everyMinute()->onOneServer();
I am using Redis as my cache driver and it is working.
Then I tried two different approaches.
First Approach: Using Laravel AWS Worker package, https://packagist.org/packages/dusterio/laravel-aws-worker
I installed the package following the instructions mentioned in the doc.
Then I whitelist the worker routes mentioned in the doc in the CSRF middleware.
Then I created a cron.yml file right inside the project's root folder with the following content.
version: 1
cron:
  - name: "schedule"
    url: "/worker/schedule"
    schedule: "* * * * *"
Then I deployed my application. But the Scheduling task is not working. So I tried the second approach as follow.
Second Approach: Using Crontab
I created a .ebextensions/cronjob.config file with the following content.
files:
    "/etc/cron.d/schedule_run":
        mode: "000644"
        owner: root
        group: root
        content: |
            * * * * * root . /opt/elasticbeanstalk/support/envvars && /usr/bin/php /var/www/html/artisan schedule:run 1>> /dev/null 2>&1
commands:
    remove_old_cron:
        command: "rm -f /etc/cron.d/*.bak"
Then I deployed my application. The second approach is not working either. What is missing in my configuration and how can I get it working?
This is my another cronjob.config file.
files:
    "/etc/cron.d/mycron":
        mode: "000644"
        owner: root
        group: root
        content: |
            * * * * * root /usr/local/bin/myscript.sh
    "/usr/local/bin/myscript.sh":
        mode: "000755"
        owner: root
        group: root
        content: |
            #!/bin/bash
            date > /tmp/date
            * * * * * root . /opt/elasticbeanstalk/support/envvars && /usr/bin/php /var/www/html/artisan schedule:run 1>> /dev/null 2>&1
            exit 0
commands:
    remove_old_cron:
        command: "rm -f /etc/cron.d/mycron.bak"