zoukankan      html  css  js  c++  java
  • 使用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

    通过浏览器管理进程

      



  • 相关阅读:
    第六章 Realm及相关对象(四) PrincipalCollection
    Java消息中间件的概述与JMS规范
    什么是红黑树?
    Mybatis逆向工程的pojo实现序列化接口的代码
    关于 Java 中 finally 语句块的深度辨析
    一道字符串变量对比值是否相等题
    java-网络编程
    java. io 流
    java.io.File 类的常用的方法
    list集合排序的两种方法
  • 原文地址:https://www.cnblogs.com/lianruihong/p/10938893.html
Copyright © 2011-2022 走看看