-
supervisord
,运行 Supervisor 时会启动一个进程 supervisord,它负责启动所管理的进程,并将所管理的进程作为自己的子进程来启动,而且可以在所管理的进程出现崩溃时自动重启。 -
supervisorctl
,是命令行管理工具,可以用来执行 stop、start、restart 等命令,来对这些子进程进行管理。 -
sudo pip install supervisor
-
-
mkdir -p /etc/etc/supervisor/conf.d
echo_supervisord_conf > /etc/supervisor/conf.d/supervisord.conf
mkdir -p /var/log/supervisor/
touch supervisord.log - 配置修改
-
[unix_http_server]
;file=/tmp/supervisor.sock ; (the path to the socket file)
;修改为 /var/run 目录,避免被系统删除
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0766 ; socket file mode (default 0700)
[supervisord]
;logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
;修改为 /var/log 目录,避免被系统删除
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.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=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
;修改为 /var/run 目录,避免被系统删除
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
...
;设置启动supervisord的用户,一般情况下不要轻易用root用户来启动,除非你真的确定要这么做
;user=chrism ; (default is current user, required if root)
...[supervisorctl]
; 必须和'unix_http_server'里面的设定匹配
;serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
;修改为 /var/run 目录,避免被系统删除
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
;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
... - 添加的进程
-
vim uwsgi.conf
; ================================
; uwsgi supervisor
; ================================
[program:uwsgi]
command=uwsgi --ini /opt/zbmbulding/uwsgi.ini
directory=/opt/zbmbulding/
# 开始等待时间
startsecs=0
# 停止等待时间
stopwaitsecs=0
user=root
stdout_logfile=/var/log/zbmbulding/uwsgi_out.log
stderr_logfile=/var/log/zbmbulding/uwsgi_err.log
autostart=true
autorestart=true
startsecs=10
priority=997 -
supervisorctl reload 重启进程配置文件
supervisorctl status 查看是否开启成功 -
错误解决
1、uwsgi出现Exited too quickly (process log may have details)
原因:supervisor 比较适合监控业务应用,且只能监控前台程序
解决方案:
之前我们在uwsgi的配置文件中设置了一个日志文件保存位置的参数:
daemonize = /home/mysite_uwsgi/mysite.log
但是这个参数的配置与Supervisor的日志输出配置是有冲突的,需要注释掉它,因为在前面加个#:
nginx出现相同的错误方式解决方式...
daemon off;
...events {
...
}http {
...
}
把配置文件的daemon改为off