supervisord 进程管家
s
supervisor
supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我们只需要将要管理进程的可执行文件的路径添加到supervisor的配置文件中就好了。此时被管理进程被视为supervisor的子进程,若该子进程异常中断,则父进程可以准确的获取子进程异常中断的信息,通过在配置文件中设置autostart=ture,可以实现对异常中断的子进程的自动重启。
安装supervisor
$ sudo apt-get install supervisor
配置文件
安装完supervisor后,输入以下命令可得到配置文件:
$ echo_supervisord_conf
或者:
$ cat /etc/supervisord/supervisord.conf
配置文件如下(分号;表示注释):
; 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
以上配置文件用到几个部分:
- [unix_http_server]:这部分设置HTTP服务器监听的UNIX domain socket
- file: 指向UNIX domain socket,即file=/var/run/supervisor.sock
- chmod:启动时改变supervisor.sock的权限
- [supervisord]:与supervisord有关的全局配置需要在这部分设置
- logfile: 指向记录supervisord进程的log文件
- pidfile:pidfile保存子进程的路径
- childlogdir:子进程log目录设为AUTO的log目录
- [supervisorctl]:
- serverurl:进入supervisord的URL, 对于UNIX domain sockets, 应设为 unix:///absolute/path/to/file.sock
- [include]:如果配置文件包含该部分,则该部分必须包含一个files键:
- files:包含一个或多个文件,这里包含了/etc/supervisor/conf.d/目录下所有的.conf文件,可以在该目录下增加我们自己的配置文件,在该配置文件中增加[program:x]部分,用来运行我们自己的程序,如下:
- [program:x]:配置文件必须包括至少一个program,x是program名称,必须写上,不能为空
- command:包含一个命令,当这个program启动时执行
- directory:执行子进程时supervisord暂时切换到该目录
- user:账户名
- startsecs:进程从STARING状态转换到RUNNING状态program所需要保持运行的时间(单位:秒)
- redirect_stderr:如果是true,则进程的stderr输出被发送回其stdout文件描述符上的supervisord
- stdout_logfile:将进程stdout输出到指定文件
- stdout_logfile_maxbytes:stdout_logfile指定日志文件最大字节数,默认为50MB,可以加KB、MB或GB等单位
- stdout_logfile_backups:要保存的stdout_logfile备份的数量
示例如下,在目录/etc/supervisor/conf.d/下创建awesome.conf,并加入:
;/etc/supervisor/conf.d/awesome.conf
[program:awesome]
command = /usr/bin/env python3 /srv/awesome/www/app.py
directory = /srv/awesome/www
user = www-data
startsecs = 3
redirect_stderr = true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups = 10
stdout_logfile = /srv/awesome/log/app.log
配置完后,先进入/srv/awesome/目录下创建log目录,之后启动supervisor:
$ sudo supervisord -c supervisor.conf
supervisor基本命令(后四个命令可以省略“-c supervisor.conf”):
supervisord -c supervisor.conf 通过配置文件启动supervisor
supervisorctl -c supervisor.conf status 查看状态
supervisorctl -c supervisor.conf reload 重新载入配置文件
supervisorctl -c supervisor.conf start [all]|[x] 启动所有/指定的程序进程
supervisorctl -c supervisor.conf stop [all]|[x] 关闭所有/指定的程序进程
执行服务(运行app.py):
$ sudo supervisorctl start awesome
如果supervisor遇到错误,可以在/var/log/supervisor/supervisord.log中查看日志;
如果app运行出现问题,可以在/srv/awesome/log/app.log中查看日志。
作者:涵仔睡觉
链接:https://www.jianshu.com/p/0226b7c59ae2
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
supervisord 进程管家的更多相关文章
- Supervisord进程管家
Supervisord进程管家 Supervisord是一个守护进程的工具,当进程意外终止或服务器掉电起来后,希望进程能够自动运行,supervisord可以很好的为我们做这件事情.同时supervi ...
- Supervisord进程管理工具
进程管理工具Supervisord Posted on 2014/06/17 by admin Supervisord 上面已经介绍了Go目前是有两种方案来实现他的daemon,但是官方本身还不支持这 ...
- supervisord进程管理工具小结
前言 昨天临近下班,发现业务队列处理不及时,正好想到不久之前,上了一个新功能:通过队列异步转发微信消息.可能是消息太多了处理不过来,没怎么多想,处理不过来了,多增加处理进程就可以了,后来发现自己so ...
- supervisord进程管理
一:简介 supervisord是一个进程管理工具,提供web页面管理,能对进程进行自动重启等操作. 优点: - 可以将非后台运行程序后台运行 - 自动监控,重启进程 缺点: - 不能管理后台运行程序 ...
- Supervisord管理进程实践
今天凑空研究了下Supervisord,这是一款linux进程管理工具,使用python开发,主要用于在后台维护进程(类似master守护进程),可以实现监控进程的状态.自动重启进程等操作,便于一些服 ...
- supervisord 小记
此篇仅用作supervisord的用法,不涉及理论说明和基础介绍 supervisor(一)基础篇 使用supervisord来管理process 进程的守护神 - Supervisor superv ...
- 进程管理工具Supervisor(一)简介与使用
Supervisor是用Python开发的一套client/server架构的进程管理程序,能做到开机启动,以daemon进程的方式运行程序,并可以监控进程状态等等. linux进程管理方式有传统的r ...
- Supervisor 安装及配置管理uwsgi进程
Supervisor介绍 Supervisor 允许其用户在UNIX类操作系统上控制多个进程. 块如下: 方便 需要为每个进程实例编写rc.d脚本通常是不方便的. rc.d脚本是进程初始化/自动启动/ ...
- supervisor进程管理的使用
介绍 Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启.它是通过fork/exec的方式把这些被管理 ...
随机推荐
- SQL各种语(持续更新)
--通过分组查询,并查询各个组下面的数据数量 SELECT cord,COUNT(*) AS s FROM View_QualityPolicy GROUP BY cord ORDER BY s DE ...
- Postman用法,了解一下
一.Postman的基础功能 二.接口请求流程 1. GET 请求 GET请求:点击Params,输入参数及value,可输入多个,即时显示在URL链接上, 所以,GET请求的请求头与请求参数如在接口 ...
- day2----python的基本类型
本文档的大致内容:(python使用版本3.6.4) 1 数字--int 2 布尔--bool 3 字符串--str 4 元祖--() 5 列表---['a','b'] 6 字典--{} 运算符: ...
- [Unity优化]UI优化(一):RaycastTarget
参考链接: http://www.manew.com/thread-100366-1-1.html https://www.jianshu.com/p/3082ebf8a342 https://blo ...
- CentOS7离线安装TIDB
首先准备一台能够联网,并且操作系统版本与正式版本完全一致的服务器. 安装思路是,通过在线方式获得所有离线安装包,然后导入到正式安装环境中去. yum install -y --downloadonly ...
- py库: PIL 、pillow(图像处理)
https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014320027235877 ...
- openx 添加新表和据库表和字段
OpenX的版本是2.8.10.在数据表加完数据库之后,还不能读取和保存字段. OpenX使用scheme来 管理数据库表和字段, 修改数据库结构同时也要修改相关schema, 一个是etc/tabl ...
- Apache 服务器 基础知识小结
Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的网页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软 ...
- DOS 和 DDOS 攻击
<一>: ICMP 协议 01: 是什么 => 互联网信心控制协议. Internet Control Message Protocol 02: 干什么 => 用于实现链路连通 ...
- C# Uditor 富文本的部署
<1> 先到http://ueditor.baidu.com/website/download.html去下载对应编程语言的版本(以.net为例) <二> 将下载下来的文件解压 ...