专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > youbbs

Ubuntu安装和使用Supervisor(进程守护)方法

发布时间: 文章来源:www.iduyao.cn 采编人员:毒药  
Supervisor 是一个用 Python 写的进程管理工具,可以很方便的对进程进行启动、停止、重启等操作。
安装命令:
apt-get install supervisor

安装成功后,会在/etc/supervisor目录下,生成supervisord.conf配置文件。
supervisord.conf示例配置:
; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

; 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]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf

进程配置会读取/etc/supervisor/conf.d目录下的*.conf配置文件,我们在此目录下创建一个goyoubbs.conf进程配置文件:
[program:goyoubbs]
directory=/www/wwwroot/iduyao.cn
command=/www/wwwroot/iduyao.cn/goyoubbs  ;建议使用前面的绝对路径。使用./goyoubbs 好像提示错误
autostart=true
autorestart=true
startretries=10
redirect_stderr=true
stdout_logfile=/www/wwwroot/iduyao.cn/iduyao.cn.log

需要注意的是,如果不是root账号,需要对这些目录进行权限设置,要不然会报一些错误(一定要在 root 账号下进行配置,要不然一系列权限引起的问题)。
$ sudo chmod 777 /var/run
$ sudo chmod 777 /etc/supervisor

接着就可以启动 Supervisord 了;

重启supervisor,让配置文件生效,然后启动goyoubbs进程:

supervisorctl reload
supervisorctl start goyoubbs

附:supervisorctl 常用命令和说明
1、supervisorctl stop program_name 停止某个进程
2、supervisorctl start program_name 启动某个进程
3、supervisorctl restart program_name 重启某个进程
4、supervisorctl stop all 停止全部进程
5、supervisorctl reload 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程
6、supervisorctl update 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
   2252阅读

其他一些配置,通过这个例子讲解

[program:meta.txn.recover.on.error]
command=/cas/bin/meta.txn.recover.on.error ; 被监控的进程路径
numprocs=1                    ; 启动几个进程
directory=/cas/bin                ; 执行前要不要先cd到目录去,一般不用
autostart=true                ; 随着supervisord的启动而启动
autorestart=true              ; 自动重启。。当然要选上了
startretries=10               ; 启动失败时的最多重试次数
exitcodes=0                 ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定)
stopsignal=KILL               ; 用来杀死进程的信号
stopwaitsecs=10               ; 发送SIGKILL前的等待时间
redirect_stderr=true          ; 重定向stderr到stdout
stdout_logfile=/var/log/supervisor/supervisord.log        ; 指定日志文件

常用命令:
supervisorctl start programxxx,启动某个进程

supervisorctl restart programxxx,重启某个进程

supervisorctl stop groupworker: ,重启所有属于名为groupworker这个分组的进程(start,restart同理)

supervisorctl stop all,停止全部进程,注:start、restart、stop都不会载入最新的配置文件。

supervisorctl reload,载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程。

supervisorctl update,根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启。

supervisor启动和停止的日志文件存放在/var/log/supervisor/supervisord.log

注意:显式用stop停止掉的进程,用reload或者update都不会自动重启

毒药   2019-06-17 18:00:15
1

[program:youbbs]
command = /srv/www/youbbs/goyoubbs -config=/srv/www/youbbs/config/config.yaml
process_name = youbbs
stopwaitsecs = 10
directory = /srv/www/youbbs
redirect_stderr=true
autostart=true
autorestart=true
stdout_logfile=/srv/logs/youbbs_out.log
stderr_logfile=/srv/logs/youbbs_err.log

毒药   2019-06-19 22:10:21
2
登录 后发表评论

热门分类:

Web开发 | Web前端 | HTML/CSS | php | ASP | JavaScript | jQuery | HTML5 | vbScript | Ajax | 网页设计 | 跨浏览器开发 | 高性能WEB开发 | Web Service | XML/SOAP | CGI | 数据库 | SQL | MySQL | NoSQL | Oracle技术 | Oracle管理 | Oracle开发 | Oracle面试 | Oracle Exception | Sql Server | Informix | Sybase | DB2 | Access | VFP | 数据仓库 | 高性能数据库开发 | 其他数据库 | 移动开发 | Android | Iphone | Windows Mobile | Symbian | BlackBerry | QT开发 | Brew | MeeGo | 移动平台 | 电信IT应用开发 | 移动应用 | Java Web开发 | J2EE | J2SE | J2ME | Java面试 | Java相关 | Eclipse | Java Exception | 企业开发 | 企业信息化 | 行业应用 | GIS | SAP | Tivoli | Lotus | Exchange | SharePoint | Dynamics CRM | K2 BPM | 报表 | 嵌入开发 | WinCE | 硬件开发 | 单片机 | 汇编语言 | 驱动开发 | Wireless | VxWorks | 应用服务器 | Apache | IIS | JBoss | WebSphere | Weblogic | ColdFusion | 研发管理 | 项目管理 | 开发过程 | 开发方法 | 软件设计 | 设计模式 | 软件架构设计 | 敏捷开发 | 微创软件开发 | CVS/SVN | VSTS | PowerDesigner | Rational | 软件测试 | C# | ASP.NET | WinForm | WCF | CLR | WPF | XNA | Visual Studio | WinRT Metro | .NET Framework | VB Dotnet | VC | .NET分析设计 | .NET组件控件 | J# | Delphi | .NET报表 | LINQ | .NET新技术 | .NET面试 | .NET相关 | DotNet Exception | Linux/Unix | Solaris | AIX | 多媒体/流媒体开发 | 多媒体设计 | 交互式开发 | Flash | 图形/图像 | 图像工具使用 | Flex | AutoCAD | Silverlight | C++ | C语言 | C++ Builder | 网络通信 | PB | Ruby/Rails | Perl/Python | Erlang | Go | Swift | Verilog | 编程 | 其他开发语言 | Open API | 信息/网络安全 | IBM云计算 | Paypal | VOIP | Google技术 | 人工智能