Mac下Supervisor进程监控管理工具的安装与配置

yipeiwu_com6年前Python基础

Supervisor 是一个类 unix 操作系统下的进程监控管理工具。

安装 Supervisor

Supervisor 是由 Python 写成,可用 Python 的包安装管理工具 pip(Python Package Index) 直接安装:

复制代码 代码如下:

sudo pip install supervisor

配置 Supervisor

Supervisor 的配置文件命名为 supervisord.conf,它为 supervisord(Supervisor 的主服务命令) 和 supervisorctl(Supervisor 的监控管理命令) 提供配置选项设置。 Supervisor 并不规定配置文件 supervisord.conf 的存放位置,Supervisor 服务启动的时候默认会在:

复制代码 代码如下:

$CWD/supervisord.conf
$CWD/etc/supervisord.conf
/etc/supervisord.conf

这几个目录位置查找配置文件 supervisord.conf。Supervisor 也提供参数 "-c" 来指定配置文件的目录路径。

在终端输入 "echo_supervisord_conf" 命令可查看 Supervisor 的默认配置的内容。

生成一份默认的配置文件:

复制代码 代码如下:

echo_supervisord_conf > /etc/supervisord.conf

这里有选择的设置了一些配置,基本够用,配置如下:

复制代码 代码如下:

[inet_http_server]
port = 127.0.0.1:9001
username = dhq
password = 123456
 
[unix_http_server]
file = /tmp/supervisor.sock
chmod = 0700
 
[supervisord]
logfile = /Users/dengjoe/.supervisor/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=10
loglevel = info
pidfile = /tmp/supervisord.pid
nodaemon = False
minfds = 1024
minprocs = 200
umask = 022
identifier = supervisor
directory = /tmp
nocleanup = true
childlogdir = /tmp
 
[supervisorctl]
serverurl = unix:///tmp/supervisor.sock
 
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
 
 
 
[program:shadowsocks]
directory = /Users/dengjoe/shadowsocks
command = /usr/bin/python /Users/dengjoe/shadowsocks/local.py
autostart = true
autorestart = true

启动 Supervisor

复制代码 代码如下:

supervisord -c /etc/supervisord.conf

参数 "-c" 表示指定 Supervisor 配置文件的路径

把 supervisord 加入系统启动服务

复制代码 代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <dict>
        <key>SuccessfulExit</key>
        <false/>
    </dict>
    <key>Label</key>
    <string>dengjoe.supervisord</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/supervisord</string>
        <string>-n</string>
        <string>-c</string>
        <string>/etc/supervisord.conf</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

启动 Supervisor 服务:

复制代码 代码如下:

launchctl load ~/Library/LaunchAgents/dengjoe.supervisord.plist

supervisorctl 监控命令

supervisorctl 是 Supervisor 自带的后台进程控制工具,下面是该命令的一些用法:

启动应用:

复制代码 代码如下:

supervisorctl start program

重新读取配置:

复制代码 代码如下:

supervisorctl update

相关文章

python制作填词游戏步骤详解

python制作填词游戏步骤详解

如何用PYTHON制作填词游戏 新建一个PYTHON文档。用JUPYTER NOTEBOOK打开即可。 print("Heart is " + color) print(noun...

python logging模块书写日志以及日志分割详解

python logging模块书写日志以及日志分割详解

本文范例是书写两个日志:错误日志(ERROR级别)和运行日志(DEBUG级别),其中运行日志每日凌晨进行分割 import logging,datetime,logging.hand...

python实现回旋矩阵方式(旋转矩阵)

我们知道Python中是没有数组 这种数据结构的,所以要想实现回旋矩阵,需要先导入一个numpy包, 它是一个由多维数组对象和用于处理数组的例程集合组成的python扩充程序库,可以用来...

浅谈pycharm的xmx和xms设置方法

PyCharm使用jre,所以设置内存使用的情况和eclipse类似。 编辑PyCharm安装目录下PyCharm 4.5.3\bin下的pycharm.exe.vmoptions文件,...

Python面向对象程序设计类的多态用法详解

本文实例讲述了Python面向对象程序设计类的多态用法。分享给大家供大家参考,具体如下: 多态 1、多态使用 一种事物的多种体现形式,举例:动物有很多种 注意: 继承是多态的前提 函数重...