supervisor简介

  一般的,我们部署一个项目,我们希望它能在挂了之后能自动重启,这时就要用守护进程了,而supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。

  运行 Supervisor 时会启动一个进程 supervisord,它负责启动所管理的进程,并将所管理的进程作为自己的子进程来启动,而且可以在所管理的进程出现崩溃时自动重启。

  supervisor安装

  我这里使用的是Ubuntu16.04,所以可以直接采用apt工具安装  

    sudo apt install supervisor

  安装完成后,在/etc目录下会有一个supervisor目录,里面有一个supervisord.conf文件和conf.d目录 ,supervisord.conf是supervisor的配置文件,conf.d是子进程的配置文件,打开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

  后面files = /etc/supervisor/conf.d/*.conf即子进程配置文件应该放的目录,这里规定.conf结尾的文件将被当做配置文件,一般的,我们也是一个程序的配置放到一个文件中

  默认情况下supervisor是开机自动启动的,在/etc/systemd/system/multi-user.target.wants/supervisor.service(这个是一个软连接)中配置有supervisor启动程序  

    [Unit]
Description=Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target [Service]
ExecStart=/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl -c /etc/supervisor/supervisord.conf $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=50s [Install]
WantedBy=multi-user.target

  如果supervisor.service这个文件不存在,我们可以新建一个supervisor.service,并将上面的内容复制过去(注意路径),或者同样使用软连接。

    #先看supervisor.service是否已经加到开机启动
sudo systemctl is-enabled supervisor.service
#添加
sudo systemctl enable supervisor.service
#验证
sudo systemctl is-enabled supervisor.service

  supervisor常用命令

  supervisor常用命令就是supervisord和supervisorctl。

  supervisord主要用来启动supervisor,查看supervisor的版本,启动用户等等,一般使用-c参数来指明启动使用的supervisor配置文件。

  supervisorctl主要用来管理子进程,因此这个命令要求supervisor是启动的,否则可能会抛出u【nix:///var/run/supervisor.sock no such file】的异常,这个时候只需要使用【sudo supervisord -c 配置文件路径】来启动supervisor,如果像上面设置了开机自启,可以使用【sudo systemctl start supervisor.service】来启动supervisor。  

    supervisorctl  #进入supervisor的交互界面

    help # 查看帮助
status # 查看程序状态
stop program_name # 关闭 指定的程序
start program_name # 启动 指定的程序
restart program_name # 重启 指定的程序
tail -f program_name # 查看 该程序的日志
reload # 重新启动配置中的程序(只是重启,不会加载修改过的配置)
update # 重启配置文件修改过的程序(修改了配置,通过这个命令加载新的配置) #program_name为空或者为all,表示所有
#也可以直接使用supervisorctl+命令的方式执行而不用进入交互界面,如:
   supervisorctl stop program_name # 关闭 指定的程序
   supervisorctlstart program_name # 启动 指定的程序

  supervisor子进程配置文件例子    

    #程序名称,终端控制时需要的标识
[program:demo]
# 运行程序的命令
command=dotnet Demo.dll --server.urls=http://*:5000
# 命令执行的目录
directory=/home/feng/demo
# 程序意外退出是否自动重启
autorestart=true
# 错误日志文件
stderr_logfile=/var/log/Demo.err.log
# 输出日志文件
stdout_logfile=/var/log/Demo.out.log
# 进程环境变量
environment=
# 进程执行的用户身份
user=feng

  添加上面的子进程文件后,执行下面的命令加载    

    #加载配置,默认执行update后会自定启动
sudo supervisorctl update
# 查看程序状态
sudo supervisorctl status
#启动demo
sudo supervisorctl start demo

supervisor安装与基本使用的更多相关文章

  1. supervisor安装和配置

    直接命令 easy_install supervisor 如果报错先安装 yum install python-setuptools,再上面一条命令: 安装成功后显示finished,我们再次进行py ...

  2. Supervisor 安装及配置管理uwsgi进程

    Supervisor介绍 Supervisor 允许其用户在UNIX类操作系统上控制多个进程. 块如下: 方便 需要为每个进程实例编写rc.d脚本通常是不方便的. rc.d脚本是进程初始化/自动启动/ ...

  3. mac下supervisor安装及简单配置

    supervisor是一个用 Python 写的进程管理工具,可以很方便的用来启动.重启.关闭进程(守护进程).可以用他来管理自己的“服务程序”. 安装 首先安装Python,Mac系统好像自带. 执 ...

  4. supervisor安装、使用详解

    supervisor是用python写的一个进程管理工具,用来启动,重启,关闭进程. 1 supervisor的安装 pip install supervisor 2 supervisor的配置文件( ...

  5. supervisor安装部署和使用实例

    Supervisord是用Python实现的一款非常实用的进程管理工具,类似于monit,monit和supervisord的一个比较大的差异是supervisord管理的进程必须由superviso ...

  6. Supervisor安装与配置(Linux/Unix进程管理工具)

    原文链接:http://blog.csdn.net/xyang81/article/details/51555473 Supervisor(http://supervisord.org/)是用Pyth ...

  7. Linux系统下 Supervisor 安装搭建(yum安装)

    安装Supervisor # 安装supervisor yum install supervisor # 打开supervisor的配置文件 vi /etc/supervisord.conf 将sup ...

  8. Linux系统下 Supervisor 安装搭建

    在 web 应用部署到线上后,需要保证应用一直处于运行状态,在遇到程序异常.报错等情况,导致 web 应用终止时,需要保证程序可以立刻重启,继续提供服务. 所以,就需要一个工具,时刻监控 web 应用 ...

  9. supervisor安装及其配置

    一.supervisor概述 supervisor是一个c/s系统,被用来在类Unix系统中监控进程状态.supervisor使用python开发. 服务端进程为supervisord,主要负责启动自 ...

  10. Supervisor安装与配置

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

随机推荐

  1. Static data members in C++

    Predict the output of following C++ program: 1 #include <iostream> 2 using namespace std; 3 4 ...

  2. my39_InnoDB锁机制之Gap Lock、Next-Key Lock、Record Lock解析

    MySQL InnoDB支持三种行锁定方式: 行锁(Record Lock):锁直接加在索引记录上面,锁住的是key. 间隙锁(Gap Lock): 锁定索引记录间隙,确保索引记录的间隙不变.间隙锁是 ...

  3. angular过滤器在html和js中的使用

    在HTML中使用格式为:{{数据 | 过滤器名称:条件一:条件二--}}:过滤条件间使用:隔开 例如: 在代码中一般格式为:  变量 = $filter("过滤器名称")(被过滤数 ...

  4. 企业级BI是自研还是采购?

    企业级BI是自研还是采购? 上一篇<企业级BI为什么这么难做?>,谈到了企业级BI项目所具有的特殊背景,以及在"破局"方面的一点思考,其中谈论的焦点主要是在IT开发项目 ...

  5. Mysql配置文件 4c8g优化

    目录 一.说明 二.配置 一.说明 以下配置适合4核8G及以下的配置,会让性能稍微提高1/3左右. 测试语句 mysqlslap -uroot -p123456 --concurrency=100 - ...

  6. Wireshark(五):TCP窗口与拥塞处理

    原文出处: EMC中文支持论坛 TCP通过滑动窗口机制检测丢包,并在丢包发生时调整数据传输速率.滑动窗口机制利用数据接收端的接收窗口来控制数据流. 接收窗口值由数据接收端指定,以字节数形式存储于TCP ...

  7. 阿里面试题: (a,b,c)组合索引, 查询语句select...from...where a=.. and c=..走索引吗?

    面试官:(a,b,c)组合索引,查询语句select...from...where a=.. and c=..走索引吗应聘者: 最佳左前缀法,如果索引了多列,要遵守最左前缀法则,否则索引失效 按最左前 ...

  8. LuoguP7859 [COCI2015-2016#2] GEPPETTO 题解

    Content 有 \(n\) 个数 \(1\sim n\).你需要在其中选若干个数.但是还有 \(m\) 个限制,第 \(i\) 个限制格式为 \(a_i\) 不能和 \(b_i\) 一起选.问你一 ...

  9. LuoguB2106 矩阵转置 题解

    Content 给定一个 \(n\times m\) 的矩阵 \(A\),求其转置 \(A^\text T\). 数据范围:\(1\leqslant n,m\leqslant 100\). Solut ...

  10. java 多线程:Callable接口;FutureTask类实现对象【Thread、Runnable、Callable三种方式实现多线程的区别】

    Callable接口介绍: Java5开始,Java提供了Callable接口,像是Runnable接口的增强版,Callable接口提供了一个 call()方法可以作为线执行体. call()方法比 ...