最近听了一场分享,里边同事介绍了一些python开发环境常用到的几种工具,其中之一就supervisord,分享后自己做了些功课,概括一下supervisord是一个什么东西呢

1. 它是一个独立的常驻内存的可以后台运行的监控,管理其他进程的东西

2. 它可以管理任何进程,掌管他们的生死,记录他们个生死变换的时间,记录他们运行吐出的各种数据,主要就是stdout,stderr的输出

3. 提供了一个很好的web页面管理这些进程的运行,查看他们的日志

废话不说了,记录下安装,使用的过程,以备后用

1. 安装

pip-2.7 install supervisor

2. 写一个程序,自己绕着跑的程序 run.sh

#!/usr/bin/bash
# coding: UTF-8 while true
do
sleep 1
echo "hi, fucker"
done

3. 找一个目录,创建supervisor的配置文件 config.conf

[inet_http_server]
port = 0.0.0.0:11316
username = hefei
password = 123456 [program:echo_fucker]
command = bash /home/hefei/codes/mywork/supervisor/run.sh
autostart = true
stdout_logfile = /home/hefei/codes/mywork/supervisor/run.log [supervisord]
logfile=/home/hefei/codes/mywork/supervisor/supervisord.log ; (main log file;default $CWD/supervisor
d.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=/home/hefei/codes/mywork/supervisor/supervisord.pid ; (supervisord pidfile;default superviso
rd.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)
;umask=022 ; (process file creation umask;default 022)
;user=chrism ; (default is current user, required if root)
;identifier=supervisor ; (supervisord identifier, default is 'supervisor')
;directory=/tmp ; (default is not to cd during start)
;nocleanup=true ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp ; ('AUTO' child log dir, default $TEMP)
;environment=KEY=value ; (key value pairs to add to environment)
;strip_ansi=false ; (strip ansi escape codes in logs; def. false) ; 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:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
serverurl=http://60.28.209.27:11316 ; use an http:// url to specify an inet socket
;username=ktep ; should be same as http_username if set
;password=123 ; should be same as http_password if set
;prompt=mysupervisor ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history ; use readline history if available ; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.

4. 启动supervisord服务,这是个常驻内存的服务,他死了,supervisor就真的死了

supervisord -c config.conf

这时候查看run.sh是不是真的起来了呢?

ps -ef | grep run.sh | grep -v grep

hefei    14252  9858  0 15:20 ?        00:00:00 bash /home/hefei/codes/mywork/supervisor/run.sh

5. 使用supervisorctl ,在命令行下管理进程

supervisorctl -c config.conf start echo_fucker

supervisorctl -c config.conf stop echo_fucker

supervisorctl -c config.conf restart echo_fucker

supervisorctl -c config.conf status echo_fucker

[~/codes/mywork/supervisor]$ supervisorctl -c config.conf help

default commands (type help <topic>):
=====================================
add    clear  fg        open  quit    remove  restart   start   stop  update
avail  exit   maintail  pid   reload  reread  shutdown  status  tail  version

就不一一解释啦

6. 使用web界面管理进程

http://xx.xx.xx.xx:11316/

几点注意的:

1. 有些程序是多进程的【master进程fork出m个子进程工作】,不大适合用supervisor管理,因为kill掉master进程后,子进程就会认init做父,再用supervisor启动就会有问题【其实我没试过】

2. supervisor如果挂了,它所管理的服务也不会死,会认init做父,如果这时候再启动supervisor,会发现被管理的服务起重了。 但是,如果被管理的服务需要监听端口。。那supervisor启动的时候,会出问题哦。【端口已经很占用,其实我没试过】

【supervisord】部署单进程服务的利器的更多相关文章

  1. 在 CentOS7 上部署 zookeeper 服务

    在 CentOS7 上部署 zookeeper 服务 1 用 SecureCRT 或 XShell 等 Linux 客户端工具连接至 CentOS7 服务器: 2 进入到 /usr/local/too ...

  2. 部署samba服务之后,在客户端用挂载访问的方式,错误信息:mount: block device //192.168.1.108/mysqldata is write-protected, mounting read-only mount: cannot mount block device //192.168.1.108/mysqldata read-only

    部署samba服务之后,在客户端用挂载访问的方式,错误信息:mount: block device //192.168.1.108/mysqldata is write-protected, moun ...

  3. 在docker里部署网络服务

    之前试着玩玩docker有一阵子了,今天算是头一回正式在docker里部署网络服务. 本来想和lxc差不多的东西那自然是手到擒来,没想到还是改了很多. 第一个遇到的问题是,远程连到docker宿主机干 ...

  4. 如何将phantomjs单独部署在服务端

    如何将phantomjs单独部署在服务端 文章目录 一. 容我分析(lao dao)几句 二. 服务端 Look here 服务端phantomjs搭建 web端搭建及如何调用phantomjs 三. ...

  5. 如何在Azure上创建和部署云服务

    Azure 管理门户提供两种方法可用来创建和部署一个云服务:快速创建和自定义创建. 本主题说明如何使用快速创建方法来创建新的云服务,然后使用上传来上载和部署一套在 Azure 的云服务.当您使用此方法 ...

  6. windows下安装Redis并部署成服务

    windows下安装Redis并部署成服务 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 一:下载 下载地址: windows版本: http ...

  7. IIS 部署WCF服务注意事项

    IIS部署WCF服务的时候经常会出现如下错误: System.ServiceModel.EndpointNotFoundException”类型的未经处理的异常在 WinformWcfHost.exe ...

  8. netcore项目在Windows部署:使用NSSM部署Windows服务

    NSSM部署Windows服务 1 准备工作 在Windows平台部署Asp.net core应用程序一般采用IIS,但是如果我们的net core应用执行的是定时任务,需要开机自启,稳定运行的话,使 ...

  9. Linux 自动化部署Rsyslog服务

    Linux 自动化部署Rsyslog服务 源码如下: #/bin/bash #该脚本用于自动化部署Ryslog服务配置 #作者:雨中落叶 #博客:https://www.cnblogs.com/yuz ...

随机推荐

  1. ASP.NET 会话状态的模式

    ASP.NET 会话状态为会话数据提供了几个不同的存储选项.每个选项都通过一个 SessionStateMode 枚举值进行识别.如下列表中描述了可用的会话状态模式: InProc 模式:把会话状态存 ...

  2. SSH returns “too many authentication failures” error – HostGator

    I am an avid fan of using HostGator for small business WordPress website hosting. I love that they u ...

  3. 高可用开源方案 Keepalived VS Heartbeat对比

    最近因为项目需要,简单的试用了两款高可用开源方案:Keepalived和Heartbeat.两者都很流行,但差异还是很大的,现将试用过程中的感受以及相关知识点简单总结一下,供大家选择方案的时候参考. ...

  4. codeforce div2 C 树状数组

    http://codeforces.com/contest/362 题目大意:给你一个序列,用冒泡排序法让他变为非递减的序列最少需要几次.在冒泡交换之间,你有一个swap操作,该swap操作是交换任意 ...

  5. linux 常用端口

    常用端口 下面的表格中列举了包括在红帽企业 Linux 中的服务.守护进程.和程序所使用的最常见的通信端口.该列表还可以在 /etc/services 文件中找到.要查看由互联网号码分派局(IANA) ...

  6. no ia32-libs

    sudo apt-get install lib32stdc++6 sudo apt-get install lib32z1 http://blog.csdn.net/wangbin_jxust/ar ...

  7. 大varchar,test,blob数据类型的优化

    set global innodb-file-format=Barracuda 其它优化,后续补充

  8. Simple But Useful Samples About 'grep' Command(简单实用的grep 命令)

    Do the following: grep -rnw '/path/to/somewhere/' -e "pattern" -r or -R is recursive, -n i ...

  9. AutoTile 自动拼接(六 大结局) 学习与实践

    昨天在网上找了一些资源图片,这回就不用担心 背景资源不多的问题了,现在我一边 制作,一边发布文章. 各种各样,500多个,这里还是特别感谢 ,万恶的资本主义,不设密码就给我分享. 在制作前,大家看下这 ...

  10. HDU ACM 1495 非常可乐(广搜BFS)

    非常可乐 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissi ...