0

Decription

I'm running php /var/www/html/artisan schedule:run on cron but it's not working.

I've added the following steps to my Dockerfile:

FROM php:7.4.1-apache
...
RUN apt-get update && apt-get install -y cron
...
COPY ./.docker/cronjobs /etc/
RUN touch /var/www/html/schedule-run.log
RUN crontab /etc/cronjobs

Then, the cron is one of the CI steps that has added to .gitlab-ci.yml.

The ./.docker/cronjobs file is like:

* * * * * date >> /var/www/html/schedule-run.log
* * * * * php /var/www/html/artisan schedule:run >> /var/www/html/schedule-run.log

Everything is ok with the first line and I can see the output of the date command at /var/www/html/schedule-run.log.


Problem

The problem is with the second line of ./.docker/cronjobs which is telling the cron that running schedule:run every minute.

I've run php /var/www/html/artisan schedule:run >> /var/www/html/schedule-run.log directory to the bash of the container then I say the output of that at /var/www/html/schedule-run.log.

In the other words, the command is ok but when the cron wanted to run it, it's not going to be run.


Environment

Docker-compose: 1.25.4, build 8d51620a
Docker: 19.03.6
Machine: Ubuntu 18.0.4 LTS

Experiance

I've checked out the following questions but the problem doesn't solve.

M. Rostami
  • 999
  • 3
  • 16
  • 27
  • 1
    Play with access level to file `artisan`. It is possible, you can run the file, but user who start cron - can't – Vasyl Zhuryk Dec 15 '20 at 12:00
  • @VasylZhuryk What do you mean by access level? | The `artisan` permission is `www-data:www-data`, does it trigger the problem? – M. Rostami Dec 15 '20 at 12:17
  • 1
    It's not permission, it's file owner (and group). But file permission can trigger problems. You have to know, which user starts cron. In case, the user is different to `www-data` - you should add user to `www-data` group or change user, who will start the cron – Vasyl Zhuryk Dec 15 '20 at 12:28
  • @VasylZhuryk Yes, you are right. – M. Rostami Dec 15 '20 at 12:34
  • Try to refolmulate your cron entry to follow the example in the [Laravel docs](https://laravel.com/docs/8.x/scheduling#running-the-scheduler): `cd /var/www/html && php artisan schedule:run >> /var/www/html/schedule-run.log` See – KazikM Dec 15 '20 at 13:01
  • @KazikM It's one of the suggestions answered [here](https://stackoverflow.com/a/22920683/6602159) that I've added to the *Experience* section. Thanks, though. – M. Rostami Dec 15 '20 at 13:08
  • Does this answer your question? [Laravel artisan cron not working](https://stackoverflow.com/questions/22917116/laravel-artisan-cron-not-working) – miken32 Dec 15 '20 at 18:19
  • @miken32 I mentioned this answer in the question, NO! – M. Rostami Dec 16 '20 at 07:45
  • The solution you came up with is exactly the same – miken32 Dec 16 '20 at 15:02
  • @miken32 The problem and difference mentioned. – M. Rostami Dec 17 '20 at 17:16

1 Answers1

0

Strangely, it has solved by the following cron (in my case ./.docker/cronjobs) file:

# the commented sections have not worked.
#* * * * * php /var/www/html/artisan schedule:run >> /var/www/html/schedule-run.log
#* * * * * /usr/local/bin/php /var/www/html/artisan schedule:run >> /var/www/html/schedule-run.log
#* * * * * cd /var/www/html/ && /usr/local/bin/php artisan schedule:run >> /var/www/html/schedule-run.log

* * * * * cd /var/www/html/ && /usr/local/bin/php artisan schedule:run

I assumed that the log access triggered the problem.

M. Rostami
  • 999
  • 3
  • 16
  • 27