supervisor使用
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使用的更多相关文章
- asp.net core 负载均衡集群搭建(centos7+nginx+supervisor+kestrel)
概述 本文目的是搭建三台asp.net core 集群, 并配上 nginx做负载均衡 首先准备要运行的源码 http://pan.baidu.com/s/1c20x0bA 准备三台服务器(或则虚 ...
- 进程监控工具supervisor 启动Mongodb
进程监控工具supervisor 启动Mongodb 一什么是supervisor Superviosr是一个UNIX-like系统上的进程监控工具. Supervisor是一个Python开发的cl ...
- Linux Supervisor 守护进程基本配置
supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控.管理进程.常用于管理与某个用户或项目相关的进程. 组成部分supervisord:服务守护进程supervisorctl ...
- supervisor的安装与简单介绍
1,介绍 Supervisor是一个进程管理工具,官方的说法 用途就是有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断.当进程中断的时候我希望能自动重新启动它,此时,我就需要 ...
- supervisor监管进程max file descriptor配置不生效的问题
配置了 sudo vim /etc/security/limits.conf * soft nofile * hard nofile 单独起进程没问题, 放到supervisor下监管启动,则报错 ...
- centos 6.7 搭建tornado + nginx + supervisor的方法(已经实践)
首先,本来不想写这篇博客了,但是我测试了很多网上的例子包括简书的,全不行,我总结原因是自己太笨,搞了俩个晚上,后来决定,自己还是写一篇记录下来,保证自己以后使用 环境: centos6.7 64 py ...
- python supervisor使用
Supervisor 是基于 Python 的进程管理工具,只能运行在 Unix-Like 的系统上,也就是无法运行在 Windows 上.Supervisor 官方版目前只能运行在 Python 2 ...
- 进程管理supervisor的简单说明
背景: 项目中遇到有些脚本需要通过后台进程运行,保证不被异常中断,之前都是通过nohup.&.screen来实现,带着能否做一个start/stop/restart/reload的服务启动的想 ...
- Linux守护进程之Supervisor
1. 什么是守护进程 在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件.由于在linux中,每个 ...
- supervisor 安装、配置、常用命令
前言 在 web 应用部署到线上后,需要保证应用一直处于运行状态,在遇到程序异常.报错等情况,导致 web 应用终止时,需要保证程序可以立刻重启,继续提供服务. 所以,就需要一个工具,时刻监控 web ...
随机推荐
- mac 下搭建php 编程环境全过程
1,打开终端, 设置root密码sudo passwd root输入密码 2, 安装 apachemac 自带apache 启动apachectl start重新启动apachectl restart ...
- 批量 kill mysql 中运行时间长的sql
1.通过information_schema.processlist表中的连接信息生成需要处理掉的MySQL连接的语句临时文件,然后执行临时文件中生成的指令 mysql> select conc ...
- php中set_time_limit()函数运用
当你的页面有大量数据时,建议使用set_time_limit()来控制运行时间,默认是30s,所以需要你将执行时间加长点. 如 set_time_limit(800) ,其中将秒数设为0 ,表示持续 ...
- Calico在Docker中的搭建
一,Multi-host网络需求 开始之前推荐两篇文章 http://xelatex.github.io/2015/11/15/Battlefield-Calico-Flannel-Weave-and ...
- poll函数
poll函数与select函数的功能基本一样,其定义如下: #include <poll.h> int poll(struct pollfd fds[], nfds_t nfds, int ...
- 渲染物体到一张UITexture上
把这个脚本挂到一个Camera上 using UnityEngine; using System.Collections; [RequireComponent(typeof(Camera))] pub ...
- 项目管理工具~Jira
作用:工程管理 提交BUG 描述,截图,记录BUG ID 自定义DashBoard 添加Gadget 自定义布局 统计要素 TimeSheet 1.组内人力使用分布 2.员工工作量 Jira 过滤器设 ...
- Effective C++ -----条款31:将文件间的编译依存关系降至最低
支持“编译依存性最小化”的一般构想是:相依于声明式,不要相依于定义式.基于此构想的两个手段是Handle classes 和 Interface classes. 程序库头文件应该以“完全且仅有声明式 ...
- 【linux】ubuntu stmp服务器配置
来源:http://blog.itpub.net/786540/viewspace-1002077/ sudo apt-get install sendmail(其中已经包含了sendmail-bin ...
- UIView CALayer 的区别
UIView与CALayer的区别,很详细 研究Core Animation已经有段时间了,关于Core Animation,网上没什么好的介绍.苹果网站上有篇专门的总结性介绍,但是似乎原理性的东西不 ...