supervisor 管理后台进程
sudo easy_install supervisor
它的配置文件使用;做为注释符
另外有点类似于nginx
使用supervisord -c supervisord.conf这样的方式在后台执行
使用supervisorctl进行命令行的控制,这个有点像redis
看了pycon上的视频,发现自已水平好菜,老外好牛,差距大,还没想到什么方法,只有多写代码来着。
以下reference:
http://lincolnloop.com/blog/2010/jun/24/automatically-running-supervisord-startup/
Automatically Running Supervisord on Startup
I really like supervisord for long-running process management. It is Python, so it is easy to install and it is easy to script with tools like Fabric. Lately I’ve been deploying smaller Django/WSGI sites with Green Unicorn behind Nginx proxied over a Unix socket which makes for a nice little setup on shared hosting and RAM starved VPSes.
After installing supervisord with something like sudo easy_install supervisor
, you’ll want to make sure it runs after you reboot your machine (and gets restarted in case it crashes). If you are on a Linux system with upstart (and have root access), you can bypass the ugly init scripts and use this simple file placed in /etc/init/supervisord.conf
to manage your supervisord process:
description "supervisord"start on runlevel [2345] stop on runlevel [!2345]respawnexec /usr/local/bin/supervisord --nodaemon --configuration /etc/supervisord.conf
Now that it is in upstart, you can start it with the command sudo start supervisord
.
If you are on shared hosting, you probably won’t have permissions to do this, but if you have access tocron
, you can make sure it gets started in case the server reboots by adding this to your cron jobs:
@reboot /my/path/to/supervisord -c /my/path/to/supervisord.conf 2>&1
In the event supervisord crashes or is killed off by a sysadmin, you’re out of luck. If this happens, you’ll want to look into having a cron job periodically poll the process pid to see if it is still alive and restart it if it is not. I haven’t needed this (yet), so that is left as an exercise for the reader :)
COMMENTS
- June 24, 2010 at 12:56 p.m. #
Simon Luijk responded:
I am using daemontools to monitor gunicorn. When I update my code I send gunicorn a SIGHUP to gracefully reload the code. This creates all sorts of problems. As expected gunicorn starts up a new process and then shuts the original process down. At which point daemontools tries to start gunicorn as it thinks gunicorn has died. I have a tempary hack which I’ll spare you from.
I have been looking for an alternative and supervisord is high on the list but I have not been able to find anything conclusive on sending signals to monitored processes. What is your experience in getting gunicorn to gracefully reload code with your setup?
- June 25, 2010 at 4:48 a.m. #
ZeissS chimed in with:
@Simon: You could use the supervisorctl tool to signal supervisord to restart the process.
- June 28, 2010 at 1:57 a.m. #
Simon Luijk chimed in with:
@ZeissS That would stop and start the process and not gracefully reload the code.
I guess my question is does supervisord get its knickers in a twist if I “kill -HUP `cat /tmp/gunicorn.pid`” like daemontools does?
Seeing that you can’t give supervisord a pid file for a process, I guess the answer is yes.
GOT SOMETHING TO SAY?
以下reference:http://blog.chinaunix.net/u2/87077/showart_2300645.html
使用supervisor监控进程 | |
|
supervisor 管理后台进程
文章分类:Python编程
参考这篇文章
加上一些notes:
1 生成默认conf文件: echo_supervisord_conf > ...
2 启动:superviserd -c 配置文件path
eg:supervised -c t.ini
配置文件ini格式
3 控制:supervisorctrl -i
进入交互模式
用 Supervisor 管理后台守护进程
![](http://blog.yangyubo.com/static/ryanberg/img/blogicons/export/16x16/clock2.png)
![](http://blog.yangyubo.com/static/ryanberg/img/blogicons/export/16x16/comment.png)
![](http://blog.yangyubo.com/static/ryanberg/img/blogicons/export/16x16/trackback.png)
![](http://blog.yangyubo.com/static/ryanberg/img/blogicons/export/16x16/tag.png)
一些虚拟主机支持跑后台守护程序, 比如 Webfaction.
在虚拟主机中管理后台守护程序没有 VPS 那么方便, VPS 是可以使用 root 权限的, 但虚拟主机则不能.
要更方便的管理后台进程, 通常需要借助一些辅助工具. 常用的管理工具有 runit, daemontools 以及 Supervisor. 其中以 Supervisor 最为易用, 功能也很完善.
安装 Supervisor
Supervisor 是一个 Python 程序, 按照 官方文档安装 就可以了.
稍加注意的是, 虚拟主机用户需要安装到他的用户目录:
easy_install supervisor --prefix=$HOME
安装完成后, 确保 $HOME/bin 目录在 $PATH 环境变量中并已经生效.
使用方法: 以 Zine 为例
Zine 可以作为后台守护程序运行, 通过 Supervisor 进行 启动/重启/失败自动重启 等控制.
Supervisor 有两个可执行程序 — supervisord 和 supervisorctl:
- supervisord 是后台管理服务器, 用来依据配置文件的策略管理后台守护进程;
- supervisorctl 用于管理员向后台管理程序发送 启动/重启/停止 等指令;
它们之间的关系就相当于 Apache 的 httpd 和 apachectl.
创建工作目录和配置文件
首先需要创建一个 Supervisor 的工作目录, 如: $HOME/deploy/supervisor/, 用来存放错误日志输出, pid 文件, socket 文件, 配置文件等.
接着是创建 配置文件, 配置文件用来指示 Supervisor 有哪些进程需要管理, 以及管理策略.
我们把配置文件命名为 supervisord.conf (也可以是其它任何文件名, 但 Supervisor 默认自动在当前目录查找该文件, 用 supervisord.conf 会为以后管理提供方便):
[supervisord] logfile = %(here)s/supervisord.log loglevel = warn pidfile = %(here)s/supervisord.pid directory = %(here)s/ childlogdir = %(here)s/childlog[unix_http_server] file = <YOU-HOME-PATH>/deploy/supervisor/supervisord.sock[rpcinterface:supervisor] ; This section is always necessary because supervisor uses RPC internally. supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface[supervisorctl] ; Must match settings in 'unix_http_server' serverurl = unix:///<YOU-HOME-PATH>/deploy/supervisor/supervisord.sock[program:blog] command = <YOU-HOME-PATH>/deploy/zine/bin/python /home/yospaly/deploy/zine/scripts/server -a 127.0.0.1 --no-reloader --no-debugger --threaded -p 6666 -I <YOU-HOME-PATH>/deploy/blog/[program:blog2] command = <YOU-HOME-PATH>/deploy/zine/bin/python /home/yospaly/deploy/zine/scripts/server -a 127.0.0.1 --no-reloader --no-debugger --threaded -p 8888 -I <YOU-HOME-PATH>/deploy/blog2/
- 配置文件的第一段用来配置 supervisord 后台管理服务器一些输出文件的路径;
- 第二段用来打开 supervisord 内部的 Socket 服务, 以便接受和处理来自控制程序 (supervisorctl) 请求;
- 第三段是必备的, 详见注释;
- 第四段告诉控制程序 (supervisorctl) 通过什么途径和 supervisord 通信;
Note
Webfaction 的用户不能随意指定 Zine 的端口号, 要使用在 Webfaction 控制面板添加新的 “Custom app (listening on port)” 后获得的一个特定端口号.
使用 supervisorctl 进行控制
在 supervisord.conf 所在的工作目录执行 supervisord 运行后台管理服务器, 如果运行失败请查看工作目录下的错误日志;
supervisord 跑起来后, supervisorctl 就可以方便的手工管理守护程序了:
supervisorctl start all supervisorctl stop blog supervisorctl restart blog2
结束语
Supervisor 是一个易用, 又不失强大的工具, 这里只涉及了 Supervisor 最基本的使用, 还有很多更加高级和有用的功能未能覆盖, 可以进一步参考 Supervisor 官方文档.
转载于:https://www.cnblogs.com/lexus/archive/2010/09/24/1833656.html
supervisor 管理后台进程相关推荐
- mysql用supervisor管理_使用Supervisor管理进程
1. Superivisor简介: Supervisor是一个C/S系统,它允许用户在类UNIX系统上监控和管理一系列的进程.你可以把一个进程以Daemon的形式用Supervisor来管理. 2. ...
- 【Redis】CentOS7下redis的安装+supervisor管理+允许远程访问+测试部署效果
一.redis的安装 第一步:下载redis安装包 wget http://download.redis.io/releases/redis-4.0.6.tar.gz 第二步:解压压缩包 tar -z ...
- docker之使用supervisor管理多个进程
docker题外话: centos7安装supervisor: 源码编译安装: 下载源码文件:supervisor-3.3.1.tar.gz 下载地址:https://pypi.python.org/ ...
- Supervisor管理hhvm进程
2019独角兽企业重金招聘Python工程师标准>>> hhvm速度很快,但由于与网站程序兼容性或hhvm本身不成熟,跑一段时间后会出现hhvm经常宕掉,而前台出现502 bad g ...
- Django使用supervisor管理celery和uwsgi实践记录 uwsgi BACKOFF Exited too quickly (process log may have details)
Django使用supervisor管理celery和uwsgi实践记录 安装下载supervisor不用多说. 直接上配置文件: vir_path标识虚拟环境路径 pro_path标识项目路径 全部 ...
- Springboot部署Nginx,配合Supervisor管理Springboot进程
Springboot部署Nginx,配合Supervisor管理Springboot进程 1.打包项目 2.项目放置目录 3.通过yum方式安装nginx,supervisor 4.配置nginx 进 ...
- 使用supervisor管理laravel队列 - 配置文件supervisord.conf
相关文章 上一篇:使用supervisor管理laravel队列 ,此篇重点性描述了我本地配置supervisor的全部过程:但是并未介绍为啥这么配置,这里,我就来记录一下配置supervisor的各 ...
- 宝塔 Supervisor管理器 自动重启守护进程
属于歪门邪道,不多BB,直接上方法 在创建的.py文件中输入以下脚本 from supervisor_main import * class Get:def __init__(self):self.p ...
- 使用supervisor 管理swoft进程
背景: 项目中遇到有些脚本需要通过后台进程运行,保证不被异常中断,之前都是通过nohup.&.screen来实现,带着能否做一个start/stop/restart/reload的服务启动的想 ...
- linux常驻进程与非常驻进程,Daemontools和Supervisor管理linux常驻进程
linux主要使用supervise来管理常驻进程.基于supervise的两个比较重要的工具是Daemontools和Supervisor. 实际上,supervise也算Daemontools的一 ...
最新文章
- Java基础篇:IO流
- 洛谷——P2035 iCow
- linux 树莓派查看ip,树莓派 常用Linux命令
- Cannot load libmkl_avx.so or libmkl_def.so
- mac命令行用sublime,vscode,atom打开目录或文件的方法
- python二级多少分过_python二级操作题与分析(2)
- HAProxy介绍及配置文件详解
- 数据仓库ETL(二)基本概念
- android代码查找图像,Android平台上利用opencv进行图像的边沿检测
- cat >> ipconf << EOF > EOF是什么意思
- java环境变量配置失败_java环境变量配置失败是怎么回事?出错解决办法分享
- python爬取凤凰新闻_Python爬虫实践(9)--爬取凤凰网汽车资讯
- Nordic--nrf52832--FDS(二)基本使用
- 网站开发的需求分析报告
- AI绘画日赚千元?百度、谷歌已入局,流水线画师要被抢单了
- Node Sass could not find a binding for your current environment
- 单目视觉定位测距的两种方式
- ARGB与RGB、RGBA的区别
- 电缆的差分特性阻抗(120欧姆)及插入损耗的测量方法
- Python网络爬虫入门案例