使用 supervisor 管理进程

http://www.cnblogs.com/smail-bao/p/5673434.html

http://ju.outofmemory.cn/entry/201847

http://cpper.info/2016/04/14/supervisor-usage.html

http://xitongjiagoushi.blog.51cto.com/9975742/1710321

http://liyangliang.me/posts/2015/06/using-supervisor/

这个可是一个好东西,以后再也不用 nohup  XXXX &  了。有了它,妈妈再也不用担心我的学习了

我这里用[root@git logs]# easy_install supervisor的方式安装,之前我也试过用pip的方式安装,但是我装好之后,创建配置文件的时候报错了,

一直也没有找到原因,希望哪位朋友看到的时候帮忙和我说一下,谢谢

或者是源码安装

wget https://pypi.python.org/packages/source/s/supervisor/supervisor-3.1.3.tar.gz --no-check-certificat

tar zxf supervisor-3.1.3.tar.gz

cd supervisor-3.1.3

python setup.py install

/usr/local/bin/echo_supervisord_conf >> /etc/supervisord.conf

装好之后

生成配置文件

echo_supervisord_conf > /etc/supervisord.conf

我们现在多虑一下看看里面有哪些有效内容

[root@zabbix ansible]# cat supervisord.conf | grep -v "^;" | grep -v "^$"
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
[supervisord]
user=root
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
#serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
###为了不将所有新增配置信息全写在一个配置文件里,这里新建一个文件夹,每个程序设置一个配置文件,相互隔离
mkdir /etc/supervisord.d/ ### 修改配置文件
vim /etc/supervisord.conf ### 加入以下配置信息
[include]
files = /etc/supervisord.d/*.conf ### 在supervisord.conf中设置通过web可以查看管理的进程,加入以下代码(默认即有,取消注释即可)
[inet_http_server]
port=9001
username=user
password=123
然后我们这里就可以使用http://IP:9001来登陆管理界面 这里我们可以选择使用脚本来启动,停止supervisor 启动脚本为
  1. wget https://github.com/Supervisor/initscripts/raw/master/redhat-init-mingalevme
[root@zabbix ~]# cat /etc/init.d/supervisor 
#!/bin/bash
#
# supervisord This scripts turns supervisord on
#
# Author: Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
# Jason Koppe <jkoppe@indeed.com> adjusted to read sysconfig,
# use supervisord tools to start/stop, conditionally wait
# for child processes to shutdown, and startup later
# Mikhail Mingalev <mingalevme@gmail.com> Merged
# redhat-init-jkoppe and redhat-sysconfig-jkoppe, and
# made the script "simple customizable".
# Brendan Maguire <maguire.brendan@gmail.com> Added OPTIONS to
# SUPERVISORCTL status call
#
# chkconfig: 345 83 04
#
# description: supervisor is a process control utility. It has a web based
# xmlrpc interface as well as a few other nifty features.
# Script was originally written by Jason Koppe <jkoppe@indeed.com>.
# # source function library
. /etc/rc.d/init.d/functions set -a PREFIX=/usr/local SUPERVISORD=$PREFIX/bin/supervisord
SUPERVISORCTL=$PREFIX/bin/supervisorctl PIDFILE=/var/run/supervisord.pid
LOCKFILE=/var/lock/subsys/supervisord OPTIONS="-c /etc/supervisord.conf" # unset this variable if you don't care to wait for child processes to shutdown before removing the $LOCKFILE-lock
WAIT_FOR_SUBPROCESSES=yes # remove this if you manage number of open files in some other fashion
ulimit -n 96000 RETVAL=0 running_pid()
{
# Check if a given process pid's cmdline matches a given name
pid=$1
name=$2
[ -z "$pid" ] && return 1
[ ! -d /proc/$pid ] && return 1
(cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1
return 0
} running()
{
# Check if the process is running looking at /proc
# (works for all users) # No pidfile, probably no daemon present
[ ! -f "$PIDFILE" ] && return 1
# Obtain the pid and check it against the binary name
pid=`cat $PIDFILE`
running_pid $pid $SUPERVISORD || return 1
return 0
} start() {
echo "Starting supervisord: " if [ -e $PIDFILE ]; then
echo "ALREADY STARTED"
return 1
fi # start supervisord with options from sysconfig (stuff like -c)
$SUPERVISORD $OPTIONS # show initial startup status
$SUPERVISORCTL $OPTIONS status # only create the subsyslock if we created the PIDFILE
[ -e $PIDFILE ] && touch $LOCKFILE
} stop() {
echo -n "Stopping supervisord: "
$SUPERVISORCTL $OPTIONS shutdown
if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then
echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
for sleep in 2 2 2 2 4 4 4 4 8 8 8 8 last; do
if [ ! -e $PIDFILE ] ; then
echo "Supervisord exited as expected in under $total_sleep seconds"
break
else
if [[ $sleep -eq "last" ]] ; then
echo "Supervisord still working on shutting down. We've waited roughly 60 seconds, we'll let it do its thing from here"
return 1
else
sleep $sleep
total_sleep=$(( $total_sleep + $sleep ))
fi fi
done
fi # always remove the subsys. We might have waited a while, but just remove it at this point.
rm -f $LOCKFILE
} restart() {
stop
start
} case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart|force-reload)
restart
RETVAL=$?
;;
reload)
$SUPERVISORCTL $OPTIONS reload
RETVAL=$?
;;
condrestart)
[ -f $LOCKFILE ] && restart
RETVAL=$?
;;
status)
$SUPERVISORCTL $OPTIONS status
if running ; then
RETVAL=0
else
RETVAL=1
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
exit 1
esac exit $RETVAL

最新文章

  1. Android USB Host与HID通讯
  2. 趣拍SDK接入问题Android
  3. [Java] JDK 系统环境变量设置 bat
  4. WPF之资源字典zz
  5. sublime3的licence(update 2016-04-14)
  6. 基于XMPP协议的手机多方多端即时通讯方案
  7. 年度十佳 DevOps 博客文章(前篇)
  8. lightoj 1243 - Guardian Knights 最小费用流
  9. 使用ExifInterface获取图片信息
  10. [BZOJ1269] [AHOI2006] 文本编辑器editor (splay)
  11. 原生js实现简单的全屏滚动
  12. 剑指Offer——栈的java实现和栈的应用举例
  13. JQGrid导出Excel文件
  14. Qt中隐藏滚动条重新实现鼠标滚轮事件wheelEvent
  15. ios webview下footer部分fixed失效问题
  16. es6三个点运算符
  17. MySQL LIMIT的使用
  18. priority_queue
  19. python之线程、进程
  20. windows下好用的markdown编辑器

热门文章

  1. 学员信息录入(StuInfoManager) 用分层实现(既MySchool后的一个案例)
  2. copy sqlserver中DATE类型的数据转化 CONVERT
  3. HYSBZ 2145 悄悄话
  4. JqueryMobile入门基础附源码下载
  5. Linux中查看各文件夹大小命令du -h --max-depth=1
  6. 事务的四个特性-ACID
  7. dos常用命令
  8. 微信公众平台JSSDK开发
  9. Android中asset文件夹和raw文件夹区别
  10. Android自动化压力测试图解教程——Monkey工具