cron -f running cron commands in a laravel app

I have a added cron process in my app fly.toml like this

[processes]
  app = ""
  cron = "cron -f"

Also added a configuration through the docker file

RUN composer install \
    && mkdir -p /etc/cron.d/ \
    && echo "MAILTO=\"\"\n* * * * * www-data /usr/bin/php /app/artisan schedule:run" > /etc/cron.d/laravel 

my laravel file inside cron.d looks like
MAILTO=""
* * * * * www-data /usr/bin/php /app/artisan schedule:run >> /app/storage/logs/cron.log 2>&1
As per fly docs cron -f will pick any configuration in any file inside /etc/cron.d in that case it should log this configuration in cron.log file but nothing works.
Any suggestion in setting up this cron would be highly appreciated.
@ fideloper-fly @ [josephxanderson] you guys had the similar issue back then If you can shed some light.

bump

Are you using fideloper/fly-laravel?

There’s a few problems with cron in the context of Docker. E.g. environment variables won’t be passed to the processes ran by cron.

You either need to use supercronic, or what I do is this:

I create a file called .fly/supervisor/scheduler.conf with this content:

[program:scheduler]
command=php /var/www/html/artisan schedule:work
priority=10
numprocs=1
autostart=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
user=www-data

Then in Dockerfile I do this:

&& cp .fly/supervisor/scheduler.conf /etc/supervisor/conf.d/scheduler.conf \

Then schedule:work will run as a supervisor process.

Note that this will run the scheduler in the same VM as the web process, which means you won’t use a second VM. Depending on your app that’s a good thing or a bad thing :stuck_out_tongue_winking_eye:

Most of my apps just do simple stuff like send a periodic email. There’s no need to run that in a dedicated VM. But if your scheduler does a lot of heavy work, then maybe consider putting that in a separate VM. But in that case, I would just run schedule:work.

Hi Yaeger,
Thanks for responding to this one.
I am using official template provided by shopify which comes with a Dockerfile you can check that out in this repo
https://github.com/Shopify/shopify-app-template-php/blob/main/Dockerfile
I tried to use supercronic but that also did not worked.
In this repo their is no directory .fly/supervisor/scheduler.conf do I need to create It in my local machine then do this && cp .fly/supervisor/scheduler.conf /etc/supervisor/conf.d/scheduler.conf \
Also if my app functionality i.e frontend backend runs smooth i dont care if it runs on single machine.

I also had tried to add process

[Processess]
 app = ""
 worker = "php artisan schedule:work"

but that did’nt work as when I monitored the worker instance it was not listening/starting the schedule:work

I also tried to clear all cache etc stuff