laradock
把定时任务放在了workspace
容器执行了, 所以我们查看一下日志docker-compose logs -f workspace
Jul 2 12:26:59 9b6ec4d18dd1 syslog-ng[12]: syslog-ng starting up; version='3.13.2'
workspace_1 | *** Booting runit daemon...
workspace_1 | *** Runit started as PID 20
workspace_1 | Jul 2 12:27:00 9b6ec4d18dd1 cron[23]: (CRON) INFO (pidfile fd = 3)
workspace_1 | Jul 2 12:27:00 9b6ec4d18dd1 cron[23]: (CRON) INFO (Skipping @reboot jobs -- not system startup)
workspace_1 | Jul 2 12:28:01 9b6ec4d18dd1 CRON[26]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
workspace_1 | Jul 2 12:29:01 9b6ec4d18dd1 CRON[60]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
workspace_1 | Jul 2 12:30:01 9b6ec4d18dd1 CRON[84]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
workspace_1 | Jul 2 12:31:01 9b6ec4d18dd1 CRON[102]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
workspace_1 | Jul 2 12:32:01 9b6ec4d18dd1 CRON[120]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
workspace_1 | Jul 2 12:33:01 9b6ec4d18dd1 CRON[157]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
workspace_1 | Jul 2 12:34:01 9b6ec4d18dd1 CRON[178]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
workspace_1 | Jul 2 12:35:01 9b6ec4d18dd1 CRON[198]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
workspace_1 | Jul 2 12:36:01 9b6ec4d18dd1 CRON[218]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1)
docker-compose exec workspace bash
/usr/bin/php /var/www/artisan schedule:run
# 如果时间刚好, 就可以执行到定时任务
# xxxx => xxx
/storage/logs
, 发现了问题,root
身份,执行任务如果有日志输入,导致日志权限修改,如果有创建目录的也导致这个问题workspace
容器里用的是laradock
用户执行,导致无法正常运行**** * * laradock /usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1
chmod -R 0777 storage
docker-compose exec --user=laradock workspace bash
laradock
用户进入容器里, 可以正常执行命令workspace
容器日志输出docker-compose logs -f --tail 100 workspace
^M
)workspace_1 | Jul 2 03:19:01 fac0b255876a CRON[344]: (CRON) info (No MTA installed, discarding output)
workspace_1 | Jul 2 03:20:01 fac0b255876a CRON[350]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /de
v/null 2>&1^M)
workspace_1 | Jul 2 03:20:01 fac0b255876a CRON[348]: (CRON) info (No MTA installed, discarding output)
workspace_1 | Jul 2 03:21:01 fac0b255876a CRON[354]: (laradock) CMD (/usr/bin/php /var/www/artisan schedule:run >> /de
v/null 2>&1^M)
Windows
和linux
换行影响的,会导致linux
不能正常识别, 导致定时任务不能触发workspace
,为防止定时任务重复触发laradock/workspace/crontab/laradock
文件里laravel
的任务调度docker-compose build workspace
docker-compose stop workspace && docker-compose up -d workspace
php-worker
容器来管理定时任务laravel-scheduler.conf.example
重命名为laravel-scheduler.conf
php-worker
容器就可以加载新的任务docker-compose restart php-worker
docker-compose exec php-worker sh
/etc/supervisor/conf.d # supervisorctl status
laravel-scheduler:laravel-scheduler_00 RUNNING pid 9, uptime 2:14:33