简体   繁体   中英

Run cron with supervisor and docker

I'm stuck on an issue with a legacy Laravel project. It uses supervisor and cron to run the scheduled tasks, but it seems that the cronjobs won't run (and have never run apparently).

This is the Dockerfile:

FROM 704666026001.dkr.ecr.eu-central-1.amazonaws.com/laravel-prod

# Copy project
COPY . /var/www/html/

# Copy cronjob setup fro laravel scheduler
COPY docker/cron/cron.txt /etc/docker/cron/cron.txt

# Copy laravel queue worker supervisor conf
COPY docker/supervisor /etc/docker/supervisor/conf

RUN mkdir -p /var/www/html/storage/framework/cache/data \
    && /usr/bin/crontab -u www-data /etc/docker/cron/cron.txt \
    && chown -R www-data:www-data /var/www/html/

In the docker/supervisor folder, there a two files: One named queue-worker.conf with:

[group:laravel]
programs=laravel-worker
priority=30

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --sleep=3 --tries=3
user=www-data
numprocs=1
startsecs=10
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

And cron.conf with:

[group:cron]
programs=crond
priority=40

[program:crond]
process_name=%(program_name)s
command=crond -f
user=www-data
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

And the file docker/cron/cron.txt has one line:

* * * * * php /var/www/html/artisan schedule:run >> /dev/null 2>&1

The docker image does build without any errors. When i run it locally, this is the output:

2020-06-16 10:21:05,045 INFO Included extra file "/etc/docker/supervisor/conf/cron.conf" during parsing
2020-06-16 10:21:05,045 INFO Included extra file "/etc/docker/supervisor/conf/nginx.conf" during parsing
2020-06-16 10:21:05,045 INFO Included extra file "/etc/docker/supervisor/conf/php-fpm.conf" during parsing
2020-06-16 10:21:05,045 INFO Included extra file "/etc/docker/supervisor/conf/queue-worker.conf" during parsing
2020-06-16 10:21:05,062 INFO RPC interface 'supervisor' initialized
2020-06-16 10:21:05,063 INFO supervisord started with pid 1
2020-06-16 10:21:06,073 INFO spawned: 'nginxd' with pid 9
2020-06-16 10:21:06,078 INFO spawned: 'php-fpmd' with pid 10
2020-06-16 10:21:06,084 INFO spawned: 'laravel-worker_00' with pid 11
2020-06-16 10:21:06,088 INFO spawned: 'crond' with pid 12
2020/06/16 10:21:06 [notice] 9#9: using the "epoll" event method
2020/06/16 10:21:06 [notice] 9#9: nginx/1.16.1
2020/06/16 10:21:06 [notice] 9#9: OS: Linux 4.19.76-linuxkit
2020/06/16 10:21:06 [notice] 9#9: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2020/06/16 10:21:06 [notice] 9#9: start worker processes
2020-06-16 10:21:06,121 INFO success: nginxd entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2020-06-16 10:21:06,121 INFO success: php-fpmd entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2020/06/16 10:21:06 [notice] 9#9: start worker process 13
2020/06/16 10:21:06 [notice] 9#9: start worker process 14
2020/06/16 10:21:06 [notice] 9#9: start worker process 15
2020/06/16 10:21:06 [notice] 9#9: start worker process 16
2020/06/16 10:21:06 [notice] 9#9: start cache manager process 17
2020/06/16 10:21:06 [notice] 9#9: start cache loader process 18
[16-Jun-2020 10:21:06] NOTICE: fpm is running, pid 10
[16-Jun-2020 10:21:06] NOTICE: ready to handle connections
2020-06-16 10:21:07,259 INFO success: crond entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2020-06-16 10:21:16,253 INFO success: laravel-worker_00 entered RUNNING state, process has stayed up for > than 10 seconds (startsecs)

It does show 'crond entered RUNNING state', but the cronjob isn't run in any way. Does anyone have an idea why? Is this setup even valid?

Thanks in advance for the help!

Supervisor stops runs if they are not doing anything for certain amount of time.

So with cron you have task only running intermittently. So it gets shut down.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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