Running Gearman Workers in the Background

坚强是说给别人听的谎言 提交于 2019-11-30 02:09:11

Ok. I found a solution to my earlier problem. It involves using Supervisord to deamonize the gearman worker(s).

Here's how to install Supervisord

apt-get install python-setuptools
easy_install supervisor
echo_supervisord_conf > /etc/supervisord.conf

Here's how to configure it (first get an init script from here and save it to /etc/init.d/supervisord), then do the following:

chmod +x /etc/init.d/supervisord
update-rc.d -f supervisord defaults

You then need to update your supervisor.conf file to tell supervisord which command you want to run as a daemon (of course, this would be your gearman worker). Below is just a sample of what you would add to your supervisord.conf file, you'll need to update it to your own specific situation.

[program:gearman]
command=/usr/bin/php php_gearman_worker.php
numprocs=1
directory=/root/gearman
stdout_logfile=/root/gearman/supervisord.log
environment=GEARMAN_USER=gearman
autostart=true
autorestart=true
user=gearman
stopsignal=KILL

When you're done, then start supervisord i.e. /etc/init.d/supervisord start.

Once you do this, your Gearman worker is now active and you can now run your gearman client via the command line or with your browser.

I hope this helps.

For background workers you can use GearmanManager by Brian Moon https://github.com/brianlmoon/GearmanManager

Another option is to use screen to put the worker task into a detached shell:

screen -d -m php worker.php
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!