幸福

如人饮水,冷暖自知

Mac下Supervisor的安装及使用

superviosr是基于python开发的一款linux平台下的通用的进程管理程序,只需要将要管理进程的可执行文件的路径添加到supervisor的配置文件中即可,此时被管理进程被视为supervisor的子进程,若该子进程异常中断,则父进程可以准确的获取子进程异常中断的信息,通过在配置文件中设置autostart=ture,可以实现对异常中断的子进程的自动重启。

 

# 通过pip安装supervisor

pip install supervisor

安装过程中可能会报些错误,我这边遇到的错误如下

matplotlib 1.3.1 requires nose, which is not installed.
Installing collected packages: meld3, supervisor
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ‘/Library/Python/2.7/site-packages/meld3-1.0.2.dist-info’
Consider using the `–user` option or check the permissions.

# 单独安装2D绘图库,解决错误
sudo python -mpip install -U matplotlib –ignore-installed six

# 创建文件夹和配置文件

mkdir /etc/supervisor
cd /etc/supervisor
echo_supervisord_conf > /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
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for ;all iface)
username=user ; (default is no username (open server))
password=123 ; (default is no password (open server))
[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.

;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris ; should be same as http_username if set
;password=123 ; should be same as http_password if set

user=supervisord

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

* 注意上述有设置“user=supervisord”,意即以当前用户身份启动服务,而不是管理员,所以需要提前创建该用户身份

 

# 创建conf.d目录

mkdir conf.d && cd conf.d

# 在conf.d目录中新建子配置文件,内容如下

;/etc/supervisor/conf.d/awesome.conf

[program:awesome]

command = /usr/bin/python /firstphp/tools/password.py
directory = /firstphp/tools
user = supervisord
startsecs = 3

redirect_stderr = true
stdout_logfile_maxbytes = 50MB
stdout_logfile_backups = 10
stdout_logfile = /firstphp/supervisor/app.log

* 确保上述配置项中,日志目录地址存在,且具备写入权限

# 启动服务

supervisord

遇到报错如下

Unlinking stale socket /var/run/supervisor.sock

查看进程

ps aux | grep supervisor

杀掉进程
pkill -f supervisord

# 重新启动服务
supervisord

# 重载配置

$ supervisorctl -c supervisord.conf
awesome FATAL Exited too quickly (process log may have details)
supervisor> reload
Really restart the remote supervisord process y/N? y
Restarted supervisord

# 访问web管理

http://127.0.0.1:9001/

# 效果如图

 

 



去打赏

您的支持将鼓励我们继续创作!

[微信] 扫描二维码打赏

[支付宝] 扫描二维码打赏

点赞
  1. 码客说道:

    有代码高亮看起来就更爽了

发表评论

电子邮件地址不会被公开。 必填项已用*标注