supervisor是Linux下一个便利的启动和监控服务的命令。

举例来说:假如我想同时管理一堆的服务,包括他们的运行和停止。我就可以使用supervisor来管理。
 
supervisor包括两个命令:supervisord和supervisorctl,分别是后台的守护进程以及命令行管理命令。要安装这两个命令只需要执行sudo apt-get install supervisor即可。
两个命令共用一个配置文件,默认是:/etc/supervisor/supervisor.conf,而supervisor.conf 通过[include] 这个section来引入其它配置文件,一般放在/etc/supervisor/conf.d目录,所以我们可以将需要的文件放到这个目录之下,并将后缀改为.conf。
 
除了默认的配置之外,一个常用的配置方式是在使用启动的时候指定特定的配置文件,配置方式为:  sudo  supervisord  -c  /path/to/supervisor.conf    ,注意,这时候的配置文件要使用绝对路径,并且配置文件要完整,否则可能会报错。
supervisord只会启动一个supervisord守护进程,剩下的管理工作都交给supervisorctl命令来完成。同样的,如果指定了某一个配置文件来启动服务,那么supervisorctl的命令也要加上相对应的路径来管理:sudo supervisorctl -c /path/to/supervisor.conf,这个命令敲下之后就会进入命令行模式,对应用进行管理。
 

典型的supervisor.conf配置如下:(配置文件的注释用分号开头)

; supervisor config file
[unix_http_server] ; supervisor与supervisorctl的通讯
file=/var/run/supervisor.sock ; (the path to the socket file) should match serverurl in section supervisorctl
chmod=0700 ; sockef file mode (default 0700) [supervisord] ; 必须有,用来配置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] ; 必须有,用于配置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 = /path/to/*.conf # other configuration files you want to include [program:api4c] ;应用程序的配置
command=/path/to/python/env/bin/gunicorn -w 1 -b 0.0.0.0:8888 wsgi:application ; 执行你的命令,不能是用于启动守护进程,因为supervisor就是用来作为守护进程的
directory=/home/ubuntu/4c-entry/api4c ; chdir to here before command run
startsecs=0 ;
stopwaitsecs=0 ;
autostart=true ; supervisord启动的时候自动运行
autorestart=true ; 当程序中断的时候是否重启 stop,true,false,unexpected
stdout_logfile=/path/to/logfile.log ; 必须已经存在
stderr_logfile=/path/to/std/err/log/for4c.err
上面是一个基本的服务,用于管理一个服务进程,包含几个必要的section:supervisord、supervisorctl、program:your_program_name、rpcinterface:supervisor、include。
这几个是一定要配置的,缺少supervisord和supervisorctl和rpcinterface:supervisor会报错,include是可选的,如果你没有引入其他的配置文件的话。
关于supervisord和supervisorctl的通讯方式有两种:一种是通过sock来传输,也就是unix_http_server的配置,另一种是inet_http_server,通过http进行通讯,详细的设置可以参考supervisor的配置文档。
 

supervisor的常用命令:

supervisord -c supervisor.conf                             通过配置文件启动supervisor
supervisorctl -c supervisor.conf status                    察看supervisor的状态
supervisorctl -c supervisor.conf reload                    重新载入 配置文件  更新后可以选择重新载入
supervisorctl -c supervisor.conf start [all] |  [appname]     启动指定/所有 supervisor管理的程序进程
supervisorctl -c supervisor.conf stop [all] | [appname] 

命令使用实例:

来源: http://chenxiaoyu.org/2011/05/31/python-supervisor.html

配置项:

[program:hello] 
command=python /home/smallfish/hello.py 
autorstart=true 
stdout_logfile=/home/smallfish/hello.log
命令
shell> sudo /etc/init.d/supervisor start   -- 启动supervisor服务 
shell> sudo supervisorctl status hello     -- 获取hello服务的状态,因为是autorstart,这里已经启动了 hello  RUNNING    pid 1159, uptime 0:20:32 
shell> sudo supervisorctl stop hello       -- 停止hello服务 hello: stopped 
shell> sudo supervisorctl stop hello       -- 再次停止hello,会有错误信息 hello: ERROR (not running) 
shell> sudo supervisorctl start hello      -- 启动hello服务 hello: started

常用的配置项:

详见: http://supervisord.org/configuration.html

Linux:supervisor命令的使用的更多相关文章

  1. Linux Supervisor的安装与使用入门---SuSE

    Linux Supervisor的安装与使用入门 在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事 ...

  2. Linux Supervisor的安装与使用入门---Ubuntun

    Linux Supervisor的安装与使用入门 在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事 ...

  3. linux 常用命令。

    /* Linux常用命令? 1 查看 ls             展示当前目录下的可见文件   ls -a         展示当前目录下所有的文件(包括隐藏的文件)   ls -l(ll)     ...

  4. linux grep命令

    linux grep命令1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expressio ...

  5. Linux常用命令(一)

    Linux常用命令 1. pwd查看当前路径(Print Working Directory)    [root@CentOS ~]# pwd/root 2. cd .. 返回上一级 .. 表示上一级 ...

  6. Linux下命令行安装weblogic10.3.6

    Linux下命令行安装weblogic10.3.6 一.安装前准备工作: 1.创建用户useradd weblogic;创建用户成功linux系统会自动创建一个和用户名相同的分组,并将该用户分到改组中 ...

  7. Linux paste命令

    Linux paste命令用于合并文件的列. paste指令会把每个文件以列对列的方式,一列列地加以合并. 语法 paste [-s][-d <间隔字符>][--help][--versi ...

  8. 20145222《信息安全系统设计基础》Linux常用命令汇总

    学习Linux时常用命令汇总 通过Ctrl+f键可在该网页搜索到你想要的命令. Linux中命令格式为:command [options] [arguments] //中括号代表是可选的,即有些命令不 ...

  9. Linux sudo 命令的应用

    .note-content { font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", STHeit ...

  10. linux 基础命令与文件管理

      Linux终端介绍 Shell提示符 Bash Shell基本语法 基本命令的使用:ls.pwd.cd 查看系统和BIOS硬件时间 Linux如何获得帮助 Linux关机命令:shutdow.in ...

随机推荐

  1. javascript sprintf方法

    转载自: http://demon.tw/programming/javascript-sprintf.html function str_repeat(i, m) { for (var o = [] ...

  2. visual studio cl -d1reportSingleClassLayout查看内存f分布

    C:\Users\Administrator\Desktop\cppsrc>cl -d1reportSingleClassLayoutTeacher virtual.cpp 用于 x86 的 M ...

  3. 拓扑排序+不是字典序的优先级排列(POJ3687+HDU4857)

    一.前言 在过去的一周里结束了CCSP的比赛,其中有一道题卡了我9个小时,各种调错都没法完整的调处来这题,于是痛下决心开始补题,这个是计划的一部分.事实上,基于错误的理解我写了若干发拓扑排序+字典序的 ...

  4. UVa 1455 Kingdom 线段树 并查集

    题意: 平面上有\(n\)个点,有一种操作和一种查询: \(road \, A \, B\):在\(a\),\(b\)两点之间加一条边 \(line C\):询问直线\(y=C\)经过的连通分量的个数 ...

  5. CMD命令简介

    cmd是command的缩写.即命令行 . 虽然随着计算机产业的发展,Windows 操作系统的应用越来越广泛,DOS 面临着被淘汰的命运,但是因为它运行安全.稳定,有的用户还在使用,所以一般Wind ...

  6. ogre3D学习基础16 -- 手动创建实体(ManualObject)

    这一节练习一下手动创建实体,用到了对象(ManualObject) 第一,依然是模板 #include "ExampleApplication.h" class Example1 ...

  7. ogre3D学习基础15 -- 创建BSP Scene Manager

    BSP(binary-space partitioning) Scene Manager(二叉空间分割)场景管理器比较适合用于室内场景. 第一,添加框架代码如下 #include "Exam ...

  8. Python subprocess.Popen中communicate()和wait()区别

    刚开始我是使用的wait(),但是当adb命令返回太多时,程序就会卡死,查询得知原因后,才使用了communicate(),communicate()返回一个元组:(stdoutdata, stder ...

  9. CentOS7安装Code::Blocks

    在CentOS7上安装Codelocks的过程. 1.安装gcc,需要c和c++两部分,默认安装下,CentOS不安装编译器的,在终端输入以下命令即可yum install gccyum instal ...

  10. Leetcode 629.K个逆序对数组

    K个逆序对数组 给出两个整数 n 和 k,找出所有包含从 1 到 n 的数字,且恰好拥有 k 个逆序对的不同的数组的个数. 逆序对的定义如下:对于数组的第i个和第 j个元素,如果满i < j且  ...