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系统 ...
随机推荐
- Spring整合Ibatis之SqlMapClientDaoSupport
前言 HibernateDaoSupport SqlMapClientDaoSupport . 其实就作用而言两者是一样的,都是为提供DAO支持,为访问数据库提供支持. 只不过HibernateD ...
- Nested Classes in C++
A nested class is a class which is declared in another enclosing class. A nested class is a member a ...
- Linux学习 - 网络命令
一.write 1 功能 给指定在线用户发信息,以Ctrl + D保存结束 2 语法 write <用户名> [信息] 二.wall(write all) 1 功能 给所有在线用户发送 ...
- SpringMVC原理分析
Spring MVC主要包括以下要点: 1:由DispatcherServlet控制的整个流程: 2:注解驱动的控制器,其中包括请求映射.数据的绑定和格式化: 3:文件上传: 4:一些杂项,如静态资源 ...
- Linux基础命令---get获取ftp文件
get 使用lftp登录ftp服务器之后,可以使用get指令从服务器获取文件. 1.语法 get [-E] [-a] [-c] [-O base] rfile [-o lfil ...
- GCD的补充
1-1 关于GCD中的创建和释放 在iOS6.0之前,在GCD中每当使用带creat单词的函数创建对象之后,都应该对其进行一次release操作. 在iOS6.0之后,GC ...
- 使用缓冲流和byte数组,拷贝文件
package com.itcast.demo05.Buffered;import java.io.*;/** * @author newcityman * @date 2019/7/28 - 17: ...
- vue文件上传及压缩(canvas实现压缩)
// 读取文件结果 afterRead(files) { let that = this; let file = files.file; if (file === undefined) { retur ...
- 安装火狐浏览器报错找不到VCRUNTIME140_1.DLL
产生原因参考及下载地址:https://cn.dll-files.com/vcruntime140_1.dll.html vcruntime140_1.dll 相关的错误可能源于多种不同原因.比如,错 ...
- <转>libevent基本使用demo
这篇文章介绍下libevent在socket异步编程中的应用.在一些对性能要求较高的网络应用程序中,为了防止程序阻塞在socket I/O操作上造成程序性能的下降,需要使用异步编程,即程序准备好读写的 ...