ubuntu安装supervisor

supervisor简介

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

安装

sudo apt-get install supervisor

配置

1.修改配置

; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[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.

[include]
files = /etc/supervisor/conf.d/*.conf

2.复制
安装成功后的supervisor会在/etc下生成一个supervisor目录和supervisor.conf文件,默认/etc/supervisor.conf为空,需要将/etc/supervisor/supervisor.conf的内容复制一份到/etc/supervisor.conf中,否则启动不了。
3.编写队列配置
默认情况下,supervisor会读取/etc/supervisor/conf.d下的所有.conf文件配置

[program:laravel-echo-server]
process_name=%(program_name)s_%(process_num)02d
command   = laravel-echo-server start --force
directory = /var/www/html/echo/
autostart = true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile_maxbytes=25MB
stderr_logfile_backups=2

查看、启动、停止、重启supervisor进程

1、更新配置后必须执行更新命令才生效

sudo supervisorctl update

2、查看supervisor进程

sudo supervisorctl status

3、启动某个supervisor进程

sudo supervisorctl start xxxx

4、停止某个supervisor进程

sudo supervisorctl stop xxxx

5、停止所有supervisor进程

sudo supervisorctl stop all

6、重启某个supervisor进程

sudo supervisorctl restart xxxx
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容