使用supervisor 管理 laravel 框架中的进程

   前言:在laravel中,经常要在项目根目录下执行 php artisan queue:work  来执行队列中的任务,由此,我们想到用supervisor来管理这个进程

   Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。它是通过fork/exec的方式把这些被管理的进程当作supervisor的子进程来启动,这样只要在supervisor的配置文件中,把要管理的进程的可执行文件的路径写进去即可。也实现当子进程挂掉的时候,父进程可以准确获取子进程挂掉的信息的,可以选择是否自己启动和报警。supervisor还提供了一个功能,可以为supervisord或者每个子进程,设置一个非root的user,这个user就可以管理它对应的进程。

  安装 supervisor

  ubuntu系统下的安装,直接使用命令 

  $ apt-get install supervisor

修改配置
 安装完了之后开始修改配置文件
$ /etc/supervisor/supervisord.conf
 
修改例子如下
访问账号 user /123 通过浏览器9001端口管理这些进程
同时创建 local-cookhome-queue-worker进程
; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)
chown=vagrant ;用户
[inet_http_server]
port=0.0.0.0:9001  ;http 访问端口
username=user ;http 账户
password=123  ;http 密码

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.
[program:local-cookhome-queue-worker] ;管理进程名
user=root   ;运行账户
command=php artisan queue:work  ;具体命令
directory=/home/vagrant/code/cookhome.local ;目录
[include]
files = /etc/supervisor/conf.d/*.conf

 supervisor 常用命令

#重启
$ service supervisor restart

#启动
$ service supervisor start 

#停止  
$ service supervisor stop
#查看所有子进程的状态: 
$ supervisorctl status

通过浏览器管理进程

  



转载于:https://www.cnblogs.com/lianruihong/p/10938893.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值