原文链接:https://www.jianshu.com/p/0226b7c59ae2

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
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

【收藏】Supervisor的作用与配置的更多相关文章

  1. Supervisor的作用与配置

    supervisor supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我们只需要将要管理进程的可执行文件的路径添加到super ...

  2. 转: Linux --- Supervisor的作用与配置

    supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我们只需要将要管理进程的可执行文件的路径添加到supervisor的配置文件中 ...

  3. SUPERVISOR进程管理器配置指南

    SUPERVISOR进程管理器配置指南1. supervisor简介1.1. 官网http://supervisord.org/ 1.2. 介绍Supervisor是一个进程控制系统. 它是一个C/S ...

  4. Supervisor 的安装与配置教程

    简介 Supervisor是一个进程控制系统. 它是一个C/S系统(注意: 其提供WEB接口给用户查询和控制), 它允许用户去监控和控制在类UNIX系统的进程. 它的目标与launchd, daemo ...

  5. Supervisor重新加载配置

    Supervisor重新加载配置启动新的进程 liaojie 发布于 1年前,共有 0 条评论 一.添加好配置文件后 二.更新新的配置到supervisord supervisorctl update ...

  6. supervisor管理进程工具配置

    Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...

  7. Linux Supervisor 守护进程基本配置

    supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控.管理进程.常用于管理与某个用户或项目相关的进程. 组成部分supervisord:服务守护进程supervisorctl ...

  8. Ubuntu14中supervisor的安装及配置

    supervisor是一款很好用的进程管理工具,其命令也很简单,其安装过程如下: Ubuntu14: 首先保证本地的Python环境是OK的,并且已经安装supervisor包,如果没有安装可以用ea ...

  9. centos 下Supervisor 守护进程基本配置

    supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控.管理进程.常用于管理与某个用户或项目相关的进程. 组成部分supervisord:服务守护进程supervisorctl ...

随机推荐

  1. 工厂模式(python)

    以字符串作为传递参数 以类名作为传递参数 来自为知笔记(Wiz)

  2. 关于 this.$route.meta.operations.includes('delete') 取不到值的问题

    原因是:src/mock/api/sys.login.js中定义的路径 要与src/router/modules/下定义的路由要一致 作用this.$route.matched可以查看匹配信息 来自为 ...

  3. vs2017 快捷键 - 总结

    1.格式化代码 先选中需要格式的代码,一般是全选[Ctrl+A]后,Ctrl+K+F[按定Ctrl不动,依序点击 K和F,然后再放开 Ctrl ] 2.多行注释 注释: 先CTRL+K,然后CTRL+ ...

  4. Leetcode系列之两数之和

    Leetcode系列之两数之和 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标.你可以假设每种输入只会对应一个答案.但是,你 ...

  5. Echart可视化学习(八)

    文档的源代码地址,需要的下载就可以了(访问密码:7567) https://url56.ctfile.com/f/34653256-527823386-04154f 正文: 新增需求 点击 2020年 ...

  6. 网络协议学习笔记(二)物理层到MAC层,交换机和VLAN,ICMP与ping原理

    概述 之前网络学习笔记主要讲解了IP的诞生,或者说整个操作系统的诞生,一旦有了IP,就可以在网络的环境里和其他的机器展开沟通了.现在开始给大家讲解关于网络底层的相关知识. 从物理层到MAC层:如何在宿 ...

  7. elasticsearch之拼音搜索

    拼音搜索在中文搜索环境中是经常使用的一种功能,用户只需要输入关键词的拼音全拼或者拼音首字母,搜索引擎就可以搜索出相关结果.在国内,中文输入法基本上都是基于汉语拼音的,这种在符合用户输入习惯的条件下缩短 ...

  8. nao机器人使用手册

    简单使用和保养 开关机和马达 开机是按一下,后来按一下相当于重启了一次程序,3是播报IP地址,5秒是关机,8秒是强制关机. 电池 3月左右不用需要取下电池.夏天5-8小时,冬天8-10小时充电.活动时 ...

  9. Qt之QColorDialog

    widget.h: #ifndef WIDGET_H #define WIDGET_H #include <QWidget> class Widget : public QWidget { ...

  10. golang中结构体中的嵌套

    package main import "fmt" type Base struct { name string } func (b *Base) m1() int { retur ...