Supervisor 安装配置

安装

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

配置

/etc/supervisord.conf说明

    ;[program:theprogramname]
    ;command=/bin/cat              ; 命令路径
    ;process_name=%(program_name)s ; 进程名称格式化
    ;numprocs=1                    ; 进程数量
    ;directory=/tmp                ; 执行目录
    ;umask=022                     ; 掩码:--- -w- -w-, 转换后rwx r-x w-x
    ;priority=999                  ; 优先级,值越高,最后启动,最先被关闭,默认值999
    ;autostart=true                ; *自动重启
    ;startsecs=1                   ; 启动延时执行,默认1秒
    ;startretries=3                ; 失败最大尝试次数
    ;autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
    ;exitcodes=0,2                 ; 当退出码是0,2时,执行重启,默认值0,2
    ;stopsignal=QUIT               ; signal used to kill process (default TERM)
    ;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
    ;stopasgroup=false             ; send stop signal to the UNIX process group (default false)
    ;killasgroup=false             ; SIGKILL the UNIX process group (def false)
    ;user=chrism                   ; #运行用户
    ;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
    ;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
    ;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
    ;stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
    ;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
    ;stdout_events_enabled=false   ; emit events on stdout writes (default false)
    ;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
    ;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
    ;stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
    ;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
    ;stderr_events_enabled=false   ; emit events on stderr writes (default false)
    ;environment=A="1",B="2"       ; process environment additions (def no adds)
    ;serverurl=AUTO                ; override serverurl computation (childutils)
Laravel 队列进程实例
    [program:demo]
    process_name=%(program_name)s_%(process_num)02d
    command=/usr/local/php7/bin/php /www/demo/artisan queue:work --queue=demo --sleep=3 --tries=3
    autostart=true
    autorestart=true
    user=root
    numprocs=3
    redirect_stderr=true
    stdout_logfile=/www/demo/storage/logs/worker.log
(inet_http_server) 配置说明

配置后可使用浏览器查看和控制进程状态

    [inet_http_server]         ; inet (TCP) server disabled by default
    port=0.0.0.0:9001          ; (ip_address:port specifier, *:port for all iface)
    username=user              ; 用户名 (default is no username (open server))
    password=123               ; 密码 (default is no password (open server))

启动和关闭

启动 supervisord
    supervisord -c /etc/supervisord.conf
查看服务器进程
    ps -ef | grep super
关闭 supervisord
    supervisorctl shutdown
重新载入配置
    supervisorctl reload
其他客户端命令
    supervisorctl status #查看程序状态
    supervisorctl stop theprogramname # 停止 theprogramname
    supervisorctl start theprogramname # 启动theprogramname
    supervisorctl restart theprogramname # 重启
    supervisorctl reread # 读取有更新(增加)的配置文件,不会启动新添加的程序
    supervisorctl update # 重启配置文件修改过的程序

设置开机启动

创建 supervisord.service
     supervisord service for systemd (CentOS 7.0+)
    # by ET-CS (https://github.com/ET-CS)
    [Unit]
    Description=Supervisor daemon

    [Service]
    Type=forking
    ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
    ExecStop=/usr/bin/supervisorctl  shutdown
    ExecReload=/usr/bin/supervisorctl  reload
    KillMode=process
    Restart=on-failure
    RestartSec=42s

    [Install]
    WantedBy=multi-user.target

supervisord.service 代码仓库: https://github.com/Supervisor/initscripts/blob/master/centos-systemd-etcs

加入开机启动
    cp supervisord.service  /usr/lib/systemd/system/supervisord.service
    systemctl enable supervisord
    systemctl is-enabled supervisord

发表评论

电子邮件地址不会被公开。 必填项已用*标注