You need to enable JavaScript to run this app. Supervisor运行Laravel队列Worker时自定义日志路径无日志写入的问题排查
优惠活动
大模型
产品
解决方案
定价
更多

Supervisor运行Laravel队列Worker时自定义日志路径无日志写入的问题排查

Supervisor托管Laravel队列Worker时自定义日志无写入的排查与修复

现有配置与环境现状

1. Supervisor全局主配置

; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700
chown=root:supervisor

[supervisord]
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/www/SITENAME.COM/storage/logs/supervisor.log

.
. 
.

[include]
files = /etc/supervisor/conf.d/*.conf

2. Laravel队列Worker自定义程序配置

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=sudo php /var/www/SITENAME.COM/artisan queue:work --sleep=5 --tries=2 --daemon
user=root
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/SITENAME.COM/storage/logs/queues.outputs.log
stderr_logfile=/var/www/SITENAME.COM/storage/logs/queues.errors.log

3. 日志文件当前权限状态

-rwxrwxrwx 1 www-data www-data    0 Dec 28 19:47 queues.errors.log
-rwxrwxrwx 1 www-data www-data    0 Dec 28 19:47 queues.outputs.log
-rwxrwxrwx 1 www-data www-data    0 Jan  2 12:34 supervisor.log

故障表现

Supervisor主服务、托管的laravel-worker进程均可正常运行,但所有自定义配置路径下的日志文件始终为0字节,无任何内容写入

核心问题定位与修复步骤

  • 第一处配置硬伤:全局[supervisord]段的childlogdir参数配置无效
    Supervisor规定childlogdir必须是存放子进程轮转日志的目录路径,当前配置直接指向了一个文件路径,会导致子进程日志流绑定链路异常,无法正常落盘。需将该参数修正为实际存在的目录,例如/var/www/SITENAME.COM/storage/logs/supervisor/,提前创建该目录并分配正确读写权限。
  • 第二处配置冗余:程序command参数内嵌套sudo调用
    程序配置已指定user=root,Supervisor本身会以root身份拉起进程,额外添加sudo会导致进程上下文的输出流句柄被重置,脱离Supervisor的日志捕获绑定链路。此时哪怕目标日志文件是777全开放权限,也因为没有实际的流写入,始终保持0字节。需删除sudo,将命令修正为:command=php /var/www/SITENAME.COM/artisan queue:work --sleep=5 --tries=2 --daemon
  • 修正完成后依次执行重载命令使配置生效:
    • supervisorctl reread
    • supervisorctl update
    • supervisorctl restart laravel-worker:*

内容的提问来源于stack exchange,提问作者graham22000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.10 13:15:00