supervisor是一个C/S系统,它可以在类unix操作系统让用户来监视和控制后台服务进程的数量,一个很重要的功能就是监控服务器的主要后台进程,并在出现问题是自动重启。

根据服务器上的python版本下载对应的setuptools

[root@test1 ~]# python -V
Python
wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg#md5=bfa92100bd772d5a213eedd356d64086
直接安装
sh setuptools-.6c11-py2..egg

下载并且安装supervisor

wget http://pypi.python.org/packages/source/s/supervisor/supervisor-3.0b1.tar.gz
tar -zxvf supervisor-.0b1.tar.gz
cd supervisor-.0b1
python setup.py install

安装setuptools后也可以
easy_install supervisor

设定supervisor配置文件

创建默认的配置文件
echo_supervisord_conf  >/etc/supervisord.conf
vi /etc/supervisord.conf

取消以下的注释,并修改IP为0.
[inet_http_server]         ; inet (TCP) server disabled by default
port=        ; (ip_address:port specifier, *:port for all iface)
username=user              ; (default is no username (open server))
password=               ; (default is no password (open server))

增加自定义的后台进程(注意进程名之间用一个:分隔)
[program:hello]
command=python /root/hello.py
priority=
numprocs=
autostart=true
autorestart=true
startretries=
stopsignal=KILL
stopwaitsecs=
redirect_stderr=true
stdout_logfile=/root/hello.log

设定supervisor启动文件

vi /etc/init.d/supervisord

#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PROGNAME=supervisord
DAEMON=/usr/bin/$PROGNAME
CONFIG=/etc/$PROGNAME.conf
PIDFILE=/tmp/$PROGNAME.pid
DESC="supervisord daemon"
SCRIPTNAME=/etc/init.d/$PROGNAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 

start()
{
        echo -n "Starting $DESC: $PROGNAME"
        $DAEMON -c $CONFIG
        echo "..."
}
stop()
{
        echo -n "Stopping $DESC: $PROGNAME"
        supervisor_pid=$(cat $PIDFILE)
        kill - $supervisor_pid
        echo "..."
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo
        exit
        ;;
esac
exit 

写一个简单的python脚本

安装web.py
easy_install web.py

vi /root/hello.py

import web
urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:
    def GET(self, name):
        if not name:
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()

启动supervisor服务,并观察hello服务状态

/etc/init.d/supervisord start

查看日志
tail -f /tmp/supervisord.log
-- ::, WARN received SIGTERM indicating exit request
-- ::, INFO waiting for :hello to die
-- ::, INFO stopped: :hello (terminated by SIGKILL)
-- ::, CRIT Supervisor running as root (no user in config file)
-- ::, INFO RPC interface 'supervisor' initialized
-- ::, CRIT Server 'unix_http_server' running without any HTTP authentication checking
-- ::, INFO daemonizing the supervisord process
-- ::, INFO supervisord started with pid
-- ::, INFO spawned:
-- ::, INFO success: :hello entered RUNNING state, process has stayed up  seconds (startsecs)

可以使用supervisorctl管理进程
upervisorctl status        查询状态
supervisorctl start hello    开启服务
supervisorctl stop hello    关闭服务

之前配置文件开启了web访问,这样可以直接通过浏览器观察和控制进程,非常方便

参考:http://supervisord.org/

supervisor使用的更多相关文章

  1. asp.net core 负载均衡集群搭建(centos7+nginx+supervisor+kestrel)

    概述 本文目的是搭建三台asp.net core 集群, 并配上 nginx做负载均衡   首先准备要运行的源码 http://pan.baidu.com/s/1c20x0bA 准备三台服务器(或则虚 ...

  2. 进程监控工具supervisor 启动Mongodb

    进程监控工具supervisor 启动Mongodb 一什么是supervisor Superviosr是一个UNIX-like系统上的进程监控工具. Supervisor是一个Python开发的cl ...

  3. Linux Supervisor 守护进程基本配置

    supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控.管理进程.常用于管理与某个用户或项目相关的进程. 组成部分supervisord:服务守护进程supervisorctl ...

  4. supervisor的安装与简单介绍

    1,介绍 Supervisor是一个进程管理工具,官方的说法 用途就是有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断.当进程中断的时候我希望能自动重新启动它,此时,我就需要 ...

  5. supervisor监管进程max file descriptor配置不生效的问题

    配置了 sudo vim /etc/security/limits.conf * soft nofile * hard nofile   单独起进程没问题, 放到supervisor下监管启动,则报错 ...

  6. centos 6.7 搭建tornado + nginx + supervisor的方法(已经实践)

    首先,本来不想写这篇博客了,但是我测试了很多网上的例子包括简书的,全不行,我总结原因是自己太笨,搞了俩个晚上,后来决定,自己还是写一篇记录下来,保证自己以后使用 环境: centos6.7 64 py ...

  7. python supervisor使用

    Supervisor 是基于 Python 的进程管理工具,只能运行在 Unix-Like 的系统上,也就是无法运行在 Windows 上.Supervisor 官方版目前只能运行在 Python 2 ...

  8. 进程管理supervisor的简单说明

    背景: 项目中遇到有些脚本需要通过后台进程运行,保证不被异常中断,之前都是通过nohup.&.screen来实现,带着能否做一个start/stop/restart/reload的服务启动的想 ...

  9. Linux守护进程之Supervisor

    1. 什么是守护进程 在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件.由于在linux中,每个 ...

  10. supervisor 安装、配置、常用命令

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

随机推荐

  1. 交叉编译inetutils并配置telnet服务

    inetutils集成了许多网络客户和服务程序,主要有,finger, ftp, ftpd, rcp, rexec, rlogin, rlogind, rsh, rshd, syslog,syslog ...

  2. PyQt4控件失去焦点和获得焦点

    #QListView控件多选设置self.ui.listView.setSelectionMode(QAbstractItemView.ExtendedSelection) #初始化QListView ...

  3. IOSGCD

    http://blog.csdn.net/duxinfeng2010/article/details/8958681/ http://kyfxbl.iteye.com/blog/1997516

  4. mysql中,主键与普通索引

    一.什么是索引?索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找到符合要求的记录.表里 ...

  5. 不懂点CAP理论,你好意思说你是做分布式的吗?

  6. STL---vector(向量)

    1 基本操作 (1)头文件#include<vector>. (2)创建vector对象,vector<int> vec; (3)尾部插入数字:vec.push_back(a) ...

  7. POJ 1308

    http://poj.org/problem?id=1308 题意:判断这是不是一棵树. 思路:这个题还是有部分坑点的.首先空树也是一棵树,还有森林不是树. 关于森林的判断我是利用并查集把每一个点压缩 ...

  8. How to take partial screenshot with Selenium WebDriver in python

    from selenium import webdriver from PIL import Image fox = webdriver.Firefox() fox.get('http://stack ...

  9. jquery checkbox 复选框多次点击判断选中状态,以及全选/取消的代码示例

    2015年12月21日 10:52:51 星期一 目标, 点击当前的checbox, 判断点击后当前checkbox是否是选中状态. html: <input type="checkb ...

  10. 【leetcode】Surrounded Regions(middle)☆

    Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...