【supervisord】部署单进程服务的利器
最近听了一场分享,里边同事介绍了一些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】部署单进程服务的利器的更多相关文章
- 在 CentOS7 上部署 zookeeper 服务
在 CentOS7 上部署 zookeeper 服务 1 用 SecureCRT 或 XShell 等 Linux 客户端工具连接至 CentOS7 服务器: 2 进入到 /usr/local/too ...
- 部署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 ...
- 在docker里部署网络服务
之前试着玩玩docker有一阵子了,今天算是头一回正式在docker里部署网络服务. 本来想和lxc差不多的东西那自然是手到擒来,没想到还是改了很多. 第一个遇到的问题是,远程连到docker宿主机干 ...
- 如何将phantomjs单独部署在服务端
如何将phantomjs单独部署在服务端 文章目录 一. 容我分析(lao dao)几句 二. 服务端 Look here 服务端phantomjs搭建 web端搭建及如何调用phantomjs 三. ...
- 如何在Azure上创建和部署云服务
Azure 管理门户提供两种方法可用来创建和部署一个云服务:快速创建和自定义创建. 本主题说明如何使用快速创建方法来创建新的云服务,然后使用上传来上载和部署一套在 Azure 的云服务.当您使用此方法 ...
- windows下安装Redis并部署成服务
windows下安装Redis并部署成服务 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 一:下载 下载地址: windows版本: http ...
- IIS 部署WCF服务注意事项
IIS部署WCF服务的时候经常会出现如下错误: System.ServiceModel.EndpointNotFoundException”类型的未经处理的异常在 WinformWcfHost.exe ...
- netcore项目在Windows部署:使用NSSM部署Windows服务
NSSM部署Windows服务 1 准备工作 在Windows平台部署Asp.net core应用程序一般采用IIS,但是如果我们的net core应用执行的是定时任务,需要开机自启,稳定运行的话,使 ...
- Linux 自动化部署Rsyslog服务
Linux 自动化部署Rsyslog服务 源码如下: #/bin/bash #该脚本用于自动化部署Ryslog服务配置 #作者:雨中落叶 #博客:https://www.cnblogs.com/yuz ...
随机推荐
- 使用Chrome DevTools的Timeline和Profiles提高Web应用程序的性能
来源: http://www.oschina.net/translate/performance-optimisation-with-timeline-profiles 我们都希望创建高性能的Web应 ...
- accept: Invalid argument linux 网络编程
今天测试一个本地网络通讯,在ubuntu虚拟机下出现的问题,警报:accept: Invalid argument 初始化地方: socklen_t clilen;struct sockaddr_in ...
- js.map error
1. 问题: 1.1 通过bower install 的components 许多在运行的时候报404无法找到js.map文件, 如图: 2. 分析: 2.1 查看 ...
- OpenGL ES着色器语言之着色概览(官方文档)
OpenGL ES着色器语言之着色概览(官方文档第二章) 事实上,OpenGL ES着色语言是两种紧密关联的语言.这些语言用来在OpenGL ES处理管线的可编程处理器创建着色器. 在本文档中,除非另 ...
- SELinux(Security-Enhanced Linux)
http://blog.csdn.net/myarrow/article/details/9839377 Security-Enhanced Linux(SELinux)的历史 一个小历史将有助于帮助 ...
- Debian下VIM的安装和配置
1.安装 apt-get install vim 2.配置 这是我的vim 配饰文件,基本的功能都能实现,在这里做一个备份,省的以后重装系统还要到处找这个配置文件(/etc/vim/vimrc) : ...
- GameUnity 2.0 发布倒计时
万众期待的 gameunity 网络游戏框架 已经完成了,现在在最后的检验调试阶段. 因为版本 改动非常之大,所以 版本号 从0.2版本 改成 2.0版本. gameunity事件部分,一如既往保持高 ...
- TForm类有关属性简介
http://www.cnblogs.com/pchmonster/archive/2012/01/02/2310377.html
- 仿照微信的界面,即ViewPager+Fragment的结合使用
主布局文件: android:drawableTop="@drawable/weixin_bg"用的是状态选择器,所以要写4个状态选择器,图片的 <RelativeLayou ...
- Redis 从数据库配置
通过持久化功能,Redis保证了即使在服务器重启的情况下也不会损失(或少量损失)数据.但是由于数据是存储在一台服务器上的,如果这台服务器的硬盘出现故障,也会导致数据丢失.为了避免单点故障,我们希望将数 ...