Supervisord是用Python实现的一款非常实用的进程管理工具,在批量服务化管理时特别有效。可以将非Daemon的应用转为daemon程序。关于supervisord的安装和配置,在网上已经有很多现成的帖子,我这里就不重复了。

在centos和rhel的环境下,我们一般是用chkconfig来管理服务的启动停止、开机自启动等。下面我列出Supervisord的服务脚本。

1. 执行如下命令:

vim /etc/init.d/supervisord

2.输入如下内容:

注意:该文件中的如下几个变量,都需要根据你实际的目录来改写。

PREFIX=/usr/local

SUPERVISORD=$PREFIX/bin/supervisord      ##supervisord   程序的安装路径

SUPERVISORCTL=$PREFIX/bin/supervisorctl  ##supervisorctl 程序的安装路径

PIDFILE=/var/supervisor/supervisord.pid   ##需要先创建/var/supervisor目录

LOCKFILE=/var/supervisor/supervisord.lock

OPTIONS="-c /etc/supervisord.conf"   ##配置文件的路径

#!/bin/bash
#
# supervisord This scripts turns supervisord on
# 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.
# # source function library
. /etc/rc.d/init.d/functions set -a PREFIX=/usr/local SUPERVISORD=$PREFIX/bin/supervisord
SUPERVISORCTL=$PREFIX/bin/supervisorctl PIDFILE=/var/supervisor/supervisord.pid
LOCKFILE=/var/supervisor/supervisord.lock 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

保存完毕之后,可以执行以下命令修改文件权限:

chmod 777 /etc/init.d/supervisord

/etc/init.d/supervisord  start

这样,supervisor就启动了。

3. 配置开机启动

执行以下命令:

chkconfig supervisord  on

可以以下命令查看是否成功

chkconfig --list | grep  supervisord

python之supervisord启动脚本的更多相关文章

  1. python 设置开机启动脚本

    1.创建python_auto.bat的快捷方式,放入启动项: C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\ ...

  2. python制作一键启动脚本

    我们的系统环境或许没有Python环境,又想使用脚本,这就要使该脚本能脱离Python环境独立运行,比如说将该脚本打包成exe可执行文件等.那么怎么做呢?你可能想到py2exe和pyinstaller ...

  3. 自定义程序启动脚本加入到supervisord下管理

    ubuntu14.04 系统,直接通过apt-get安装即可 apt-get install supervisord 官网:http://www.supervisord.org/ 主配置文件 这个配置 ...

  4. 【Linux.Python】Python进程后台启动

    嗯,比较忧伤. 前几天写了个tornado,启动了,很开心,后来每天要用时都发现it是kill掉的.好吧,是我太蠢啦.百度了下资料 python的启动方式: 1 python yourfile.py ...

  5. Spark配置&启动脚本分析

    本文档基于Spark2.0,对spark启动脚本进行分析. date:2016/8/3 author:wangxl Spark配置&启动脚本分析 我们主要关注3类文件,配置文件,启动脚本文件以 ...

  6. Jenkins|简单Job配置|启动脚本|测试报告

    目录 1.Jenkins安装 2.Jenkins启动脚本 3.节点配置 4.任务配置 5.集成HTML测试报告 1.Jenkins安装 操作环境:Ubuntu jenkins针对windows,ubu ...

  7. Apollo 启动脚本解析

    Apollo 启动脚本解析 sudo service docker start -- 是在ubuntu14.04中打开 在dev_start.sh脚本中会调用restart_map_volume.sh ...

  8. Spark学习之路 (十五)SparkCore的源码解读(一)启动脚本

    一.启动脚本分析 独立部署模式下,主要由master和slaves组成,master可以利用zk实现高可用性,其driver,work,app等信息可以持久化到zk上:slaves由一台至多台主机构成 ...

  9. 转:python常用运维脚本实例

    python常用运维脚本实例 转载  file是一个类,使用file('file_name', 'r+')这种方式打开文件,返回一个file对象,以写模式打开文件不存在则会被创建.但是更推荐使用内置函 ...

随机推荐

  1. UI:UINavigationController、界面通信

    IOS中实现对控制器的管理的控制器有:UINavigationController 和 UITableBarController 两个控制器.下面是主要学习前者. 参考 ⼀.UINavigationC ...

  2. Android - Facebook KeyHash 設定

    转自:http://www.dotblogs.com.tw/newmonkey48/archive/2014/04/17/144779.aspx App要使用Facebook 分享時,設要在Faceb ...

  3. Programming pages of Jasper Neumann

    http://programming.sirrida.de/ Discussion topics Bit permutations Download source files List of func ...

  4. CSS Gradient文字效果

    你想创建的标题没有渲染和Photoshop每个标题吗?这里是一个简单的CSS技巧向您展示如何创建渐变文字效果,PNG图像(纯CSS,没有Javascript或Flash).你所需要的是一个空的< ...

  5. 使用UILocalizedIndexedCollation实现区域索引排序 及 不显示没有数据的区域

    UILocalizedIndexedCollation可以实现区域排序,类似通讯录的样式. //首先进行初始化 locationCollation = [UILocalizedIndexedColla ...

  6. Codeforces Round #335 (Div. 2) D. Lazy Student 构造

    D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...

  7. OpenGL中的功能与OSG对应功能 (摘)

    将OpenGL中的功能与OSG对应功能进行列举: OpenGL function OpenSceneGraph implementation glClear( GLbitfield mask ) os ...

  8. 云服务器 ECS Linux 系统添加“回收站”

    删除是危险系数很高的操作,一旦误删可能会造成难以估计的损失.在云服务器 ECS Linux 系统中这种危险尤为明显.比如,一条简单的语句:rm –rf /* 就会把整个系统全部删除,而 Linux 并 ...

  9. Linux中的svn客户端RabbitVCS-2

    我们都知道,自从svn出道以来,很多人都预言,cvs将会被其取代.就如同他们预言maven要取代ant一样.可见,svn的流行.在Windows中,最常用到的开源免费的svn客户端就是Tortoise ...

  10. mysql数据类型区别

    create table t1(c1 float(10,2), c3 decimal(10,2)); insert into t1 values(1234567.23, 1234567.23,1234 ...