我已经使用数据库设置了Laravel Queue,并配置了Supervisor使其保持运行,但是过一会它停止处理队列。

我正在使用Mail::queue发送电子邮件。如果我通过SSH进入服务器并运行php /home/my/path/to/artisan --env=production --timeout=240 queue:listen --tries=5,则它可以正常工作并且可以发送电子邮件。但是显然我不想通过SSH来处理电子邮件,我希望队列运行24/7,因此我安装了supervisor来管理它。我已经编辑了supervisord.conf文件,以包含以下程序:

[program:laravel_queue]
command=php /home/my/path/to/artisan --env=production --timeout=240 queue:listen --tries=5
autostart=true
autorestart=true
logfile=/var/log/laraqueue.log

当我启动该程序时,它就会发送电子邮件。但是,经过一段时间(通常是第二天)后,电子邮件将不会发送。我检查数据库,作业表已填满。当我通过SSH进入服务器并运行supervisorctl status时,我得到:
laravel_queue  RUNNING    pid 21081, uptime 2 days, 23:18:51

这是因为周末已经运行了2天,今天(星期一)不工作。显然它没有在运行,那么如何监督我发现它没有在运行并重新启动它?

如果我使用supervisorctl restart laravel_queue手动重新启动它,因为它没有运行,supervisor无法停止它,并且似乎挂起,直到按CTRL + C为止。这时,我得到了一个我不理解的回溯:
Traceback (most recent call last):
  File "/usr/bin/supervisorctl", line 6, in <module>
    main()
  File "/usr/lib/python2.6/site-packages/supervisor/supervisorctl.py", line 598, in main
    c.onecmd(" ".join(options.args))
  File "/usr/lib/python2.6/site-packages/supervisor/supervisorctl.py", line 86, in onecmd
    return func(arg)
  File "/usr/lib/python2.6/site-packages/supervisor/supervisorctl.py", line 467, in do_restart
    self.do_stop(arg)
  File "/usr/lib/python2.6/site-packages/supervisor/supervisorctl.py", line 433, in do_stop
    result = supervisor.stopProcess(processname)
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.6/xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.6/site-packages/supervisor/options.py", line 1309, in request
    errcode, errmsg, headers = h.getreply()
  File "/usr/lib64/python2.6/httplib.py", line 1064, in getreply
    response = self._conn.getresponse()
  File "/usr/lib64/python2.6/httplib.py", line 990, in getresponse
    response.begin()
  File "/usr/lib64/python2.6/httplib.py", line 391, in begin
    version, status, reason = self._read_status()
  File "/usr/lib64/python2.6/httplib.py", line 349, in _read_status
    line = self.fp.readline()
  File "/usr/lib64/python2.6/socket.py", line 433, in readline
    data = recv(1)
KeyboardInterrupt

再次检查状态将报告队列已停止,因此我运行supervisorctl start laravel_queue,并得到与运行重新启动时相同的挂起,但由于处理作业和发送电子邮件而已挂起。如果再次按CTRL + C,将得到与上述相同的回溯。

日志

一整夜后,我已经检查了laraqueue日志。我今天早上试图发送电子邮件,而工作表正坐在那里等待处理。日志中充满了以下内容:
X-Powered-By: PHP/5.6.10^M
Content-type: text/html; charset=UTF-8^M
^M

而已。只是很多重复而已。

我检查了主管日志,它仅报告laravel_queue成功启动。为了完成,日志为:
2015-10-21 14:25:24,997 INFO /var/tmp/supervisor.sock:Medusa (V1.1.1.1) started at Wed Oct 21 14:25:24 2015
    Hostname: <unix domain socket>
    Port:/var/tmp/supervisor.sock
2015-10-21 14:25:25,099 CRIT Running without any HTTP authentication checking
2015-10-21 14:25:25,107 INFO daemonizing the process
2015-10-21 14:25:25,108 INFO supervisord started with pid 3407
2015-10-21 14:25:25,115 INFO spawned: 'laravel_queue' with pid 3409
2015-10-21 14:25:26,729 INFO success: laravel_queue entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

更新

将主管更新为最新版本后,我仍然遇到相同的问题。 laraqueue.log的内容与以前相同,没有任何用处。但是,主管日志这次有更多内容:
2015-10-22 10:19:59,454 CRIT received SIGTERM indicating exit request
2015-10-22 10:19:59,454 INFO waiting for laravel_queue to die
2015-10-22 10:19:59,460 INFO stopped: laravel_queue (terminated by SIGTERM)
2015-10-22 10:19:59,460 INFO received SIGCLD indicating a child quit
2015-10-22 10:26:02,019 CRIT Supervisor running as root (no user in config file)
2015-10-22 10:26:02,085 CRIT Server 'inet_http_server' running without any HTTP authentication checking
2015-10-22 10:26:02,092 INFO daemonizing the supervisord process
2015-10-22 10:26:02,093 INFO supervisord started with pid 17268
2015-10-22 10:26:03,105 INFO spawned: 'laravel_queue' with pid 17269
2015-10-22 10:26:04,107 INFO success: laravel_queue entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2015-10-22 10:37:22,157 WARN received SIGTERM indicating exit request
2015-10-22 10:37:22,157 INFO waiting for laravel_queue to die
2015-10-22 10:37:22,163 INFO stopped: laravel_queue (terminated by SIGTERM)

有几个主管收到退出请求并启动备份请求的实例,然后日志的结尾位于停止队列的上方,但由于某种原因不再启动。我已经检查了laravel日志(在存储/日志中),但是这段时间里什么也没有。

最佳答案

检查您拥有的Supervisor版本。已知有些软件包管理器会忘记更新Supervisor。我认为您的问题将通过更新Supervisor来解决。例如,Supervisor的v2.1是2007年发布的,仍在某些软件包中。

Supervisor的当前版本是v3.13,尽管有人说(请参阅底部的引用)v3是最后一个稳定版本。

检查您使用的Supervisor版本

[root@test supervisor]# yum list | grep supervisor

比较显示的版本:https://pypi.python.org/pypi/supervisor

删除并安装(易于安装很不错)
[root@test ~]$ yum remove supervisor
[root@test ~]$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | sudo python
[root@test ~]$ sudo easy_install supervisor
Searching for supervisor
Reading https://pypi.python.org/simple/supervisor/
Best match: supervisor 3.0

更新:

请花一点时间在这里看看,这是值得(http://ahmed.amayem.com/running-a-node-js-app-ghost-in-the-background-continuously-with-supervisor-supervisord/)。尽管他与Supervisor一起运行node.js/ghost,但我认为这并不重要,因为这全都与Supervisor有关!

引用:
https://github.com/Supervisor/supervisor/issues/165

http://ahmed.amayem.com/running-a-node-js-app-ghost-in-the-background-continuously-with-supervisor-supervisord/

http://ahmed.amayem.com/woes-of-using-an-outdated-supervisord-to-run-a-node-js-app-ghost/

关于php - Laravel带有Supervisor的队列,正在运行但不处理作业,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33217269/

10-12 03:47