1,安装: #brew install supervisor
默认会安装在/usr/local/Cellar/supervisor目录
2,在etc下面新建supervisor.conf 文件,复制下面的代码(部分需要自行修改)
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #e5d872; background-color: #272821 }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #e5d872; background-color: #272821; min-height: 15.0px }
span.s1 { }
[inet_http_server]
port = 127.0.0.1:9001
username = harris
password = 123456
[unix_http_server]
file = /tmp/supervisor.sock
chmod = 0700
[supervisord]
logfile = /opt/logs/supervisor/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=10
loglevel = info
pidfile = /tmp/supervisord.pid
nodaemon = False
minfds = 1024
minprocs = 200
umask = 022
identifier = supervisor
directory = /tmp
nocleanup = true
childlogdir = /tmp
[supervisorctl]
serverurl = unix:///tmp/supervisor.sock
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[program:laravelworker]
process_name = %(program_name)s_%(process_num)02d
command = /usr/local/bin/artisan.sh queue:work --sleep=3 --tries=3
autostart = true
autorestart = true
user = phpadmin
numprocs = 8
redirect_stderr = true
stdout_logfile = /opt/logs/supervisor/worker.log
注意:
1,上面的几个日志目录必须存在,可以修改位自己的目录
2,program里的user是系统的一个用户名,不然会报错
3,/usr/local/bin/artisan.sh queue:work --sleep=3 --tries=3 这行代码是指向laravel的队列命令
4,artisan.sh脚本需要自己实现,大家的php目录,项目目录都不一样,但都是实现cd到项目的目录,php artisan $1 这个功能即可
3,启动服务 #supervisord -c /etc/supervisord.conf
4,修改了配置,重新读取配置:
#supervisorctl update
最后在laravel里往队列里添加任务即可了
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #e5d872; background-color: #272821 }
span.s1 { }