【发布时间】:2022-03-25 17:04:05
【问题描述】:
我遇到了一个遗留 Laravel 项目的问题。它使用主管和 cron 来运行计划任务,但似乎 cronjobs 不会运行(并且显然从未运行过)。
这是 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/
在 docker/supervisor 文件夹中,有两个文件: 一个名为 queue-worker.conf 的文件:
[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
还有 cron.conf:
[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
并且文件 docker/cron/cron.txt 有一行:
* * * * * php /var/www/html/artisan schedule:run >> /dev/null 2>&1
docker 镜像确实构建没有任何错误。当我在本地运行它时,这是输出:
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)
它确实显示“crond 进入运行状态”,但 cronjob 没有以任何方式运行。 有谁知道为什么?这个设置是否有效?
提前感谢您的帮助!
【问题讨论】:
-
所以在本地一切正常,但在生产中却不行?
-
不,我的意思是图像构建并运行良好,但 cronjob 似乎没有运行。在本地和生产中。
-
您在作业和 cron 作业上遇到过同样的问题吗?
-
是的,它们都因某种原因无法运行,但没有任何错误
-
如果您手动运行命令,它们会起作用吗?例如,如果您转到终端并粘贴
php /var/www/html/artisan schedule:run >> /dev/null 2>&1?
标签: laravel docker cron supervisord