supervisor安装与基本使用
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安装与基本使用的更多相关文章
- supervisor安装和配置
直接命令 easy_install supervisor 如果报错先安装 yum install python-setuptools,再上面一条命令: 安装成功后显示finished,我们再次进行py ...
- Supervisor 安装及配置管理uwsgi进程
Supervisor介绍 Supervisor 允许其用户在UNIX类操作系统上控制多个进程. 块如下: 方便 需要为每个进程实例编写rc.d脚本通常是不方便的. rc.d脚本是进程初始化/自动启动/ ...
- mac下supervisor安装及简单配置
supervisor是一个用 Python 写的进程管理工具,可以很方便的用来启动.重启.关闭进程(守护进程).可以用他来管理自己的“服务程序”. 安装 首先安装Python,Mac系统好像自带. 执 ...
- supervisor安装、使用详解
supervisor是用python写的一个进程管理工具,用来启动,重启,关闭进程. 1 supervisor的安装 pip install supervisor 2 supervisor的配置文件( ...
- supervisor安装部署和使用实例
Supervisord是用Python实现的一款非常实用的进程管理工具,类似于monit,monit和supervisord的一个比较大的差异是supervisord管理的进程必须由superviso ...
- Supervisor安装与配置(Linux/Unix进程管理工具)
原文链接:http://blog.csdn.net/xyang81/article/details/51555473 Supervisor(http://supervisord.org/)是用Pyth ...
- Linux系统下 Supervisor 安装搭建(yum安装)
安装Supervisor # 安装supervisor yum install supervisor # 打开supervisor的配置文件 vi /etc/supervisord.conf 将sup ...
- Linux系统下 Supervisor 安装搭建
在 web 应用部署到线上后,需要保证应用一直处于运行状态,在遇到程序异常.报错等情况,导致 web 应用终止时,需要保证程序可以立刻重启,继续提供服务. 所以,就需要一个工具,时刻监控 web 应用 ...
- supervisor安装及其配置
一.supervisor概述 supervisor是一个c/s系统,被用来在类Unix系统中监控进程状态.supervisor使用python开发. 服务端进程为supervisord,主要负责启动自 ...
- Supervisor安装与配置
Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...
随机推荐
- Oracle trunc和round的区别
1.关于trunc 和round函数比较 整体概括: round函数 四舍五入trunc函数 直接截取 对于时间: Round函数对日期进行"四舍五入",Trunc函数对日期进行截 ...
- spring注解-bean生命周期
https://www.jianshu.com/p/70b935f2b3fe bean的生命周期 bean创建---初始化----销毁的过程 容器管理bean的生命周期 对象创建:容器启动后调用bea ...
- Type of 'this' pointer in C++
In C++, this pointer is passed as a hidden argument to all non-static member function calls. The typ ...
- Spring Boot对静态资源的映射规则
规则一:所有 " /webjars/** " 请求都去classpath:/META-INF/resources/webjars/找资源 webjars:以jar包的方式引入静态资 ...
- 【Matlab】find函数用法
find(A):返回向量中非零元素的位置 注意返回的是位置的脚标 //类似python,还是很好用的 如果是二维矩阵,是先横行后列的 b=find(a),a是一个矩阵,查询非零元素的位置 如果X是一个 ...
- 避免警报疲劳:每个 K8s 工程团队的 8 个技巧
避免警报疲劳:每个 K8s 工程团队的 8 个技巧 监控 Kubernetes 集群并不容易,警报疲劳通常是一个问题.阅读这篇文章,了解减少警报疲劳的有用提示. 如果您是随叫随到团队的一员,您可能知道 ...
- Mysql资料 数据类型
目录 一.类型 整型 浮点型 定点数 字符串 二进制数据 时间日期类型 二.长度和范围 三.使用建议 原则 存储引擎 text和blob 浮点数和定点数 四.属性 一.类型 整型 取值范围如果加了un ...
- C语言程序设计:综合设计实验一(设计一个文字游戏)
目录 C语言程序设计:综合设计实验一(设计一个文字游戏) 1.实验要求 2.设计思路 3.源码 4.后话 C语言程序设计:综合设计实验一(设计一个文字游戏) 1.实验要求 (1) 设计一个文字游戏,通 ...
- vscode 设置
{ "security.workspace.trust.enabled": false, "workbench.editor.enablePreview": f ...
- CF248A Cupboards 题解
Content 在一个走廊上有 \(2n\) 扇门,排成两列分居左右.有个人很无聊,随意地开关了一些门,使得这些门看起来十分乱.现在请开关一些门,使得这些门恢复原来整齐的状态(要么都开.要么都关.要么 ...