Unix操作系统的进程管理工具--Supervisor

Supervisor是一款用Python2编写的管理服务进程的开源工具。博主一般用它来管理在Linux上部署的Python进程。Supervisor管理进程的操作十分简单,只需要在配置文件中,配置好要管理的进程,然后启动Supervisor守护进程即可。而对进程的管理则可以在其提供的web页面上进行操作。目前版本的Supervisor只支持Python2,也就是说,目前只能在Python2环境下运行Supervisor。但是,其所管理的Python进程则不会收到限制和影响,即我们可以用Supervisor管理Python2和Python3编写的程序。

首先,我们先在Python2环境下安装Supervisor。
pip install supervisor

然后,创建保存Supervisor配置文件的路径
mkdir -p /etc/supervisor && cd /etc/supervisor

使用vim创建supervisord.conf

; supervisor config file

; ==================================  
;  celery worker supervisor example  
; ==================================  
  
[program:celery]  
; 如果使用的是虚拟环境(virtualenv等)要把celery命令路径写全  
command=/home/houbank/.conda/envs/env-py36/bin/celery worker -A APPS.ops.celery --loglevel=INFO
directory=/home/houbank/PycharmProjects/devops/  ;项目所在目录  
user=houbank
numprocs=1  
stdout_logfile=/var/log/celery/worker.log ;celery输出日志文件  
stderr_logfile=/var/log/celery/workererr.log ;celery错误输出文件  
autostart=true  
autorestart=true  
startsecs=10  
  
; Need to wait for currently executing tasks to finish at shutdown.  
; Increase this if you have very long running tasks.  
stopwaitsecs = 600  
  
; Causes supervisor to send the termination signal (SIGTERM) to the whole process group.  
stopasgroup=true  
  
; Set Celery priority higher than default (999)  
; so, if rabbitmq is supervised, it will start first.  
priority=1000

[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

[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0:9001          ; (ip_address:port specifier, *:port for all iface)
username=root              ; (default is no username (open server))
password=123456            ; (default is no password (open server))

保存上述配置文件后,使用如下命令启动Supervisor

supervisord -c /etc/supervisor/supervisord.conf

命令中的-c参数指定的是所使用的配置文件

我们在配置文件的末尾配置了Supervisor的web管理界面,所以我们可以访问http://ip:9001访问该界面。如下图所示。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值