异常问题:使用的uwsgi管理django程序自己挂掉
解决方案:使用supervisord管理uwsgi,实现uwsgi挂掉自启
1.uwsgi.ini源文件 特别强调的是daemonize参数必须注释掉
[uwsgi]
#使用nginx连接时使用,Django程序所在服务器地址
socket=127.0.0.1:8282
#直接做web服务器使用,Django程序所在服务器地址
#http=127.0.0.1:8181
#项目目录
chdir=/home/aaa
#项目中wsgi.py文件的目录,相对于项目目录
wsgi-file=aaa/wsgi.py
#进程数
processes=2
#线程数
threads=2
#uwsgi服务器的角色
master=True
#存放进程编号的文件
pidfile=uwsgi.pid
#使进程在后台运行,并将日志打到指定的日志文件或者udp服务器
#daemonize=uwsgi.log
2.安装supervisord
yum install supervisor
#开机自启
yum enable supervisord
#启动服务
yum start supervisord
默认安装完配置文件是在/etc/supervisord.conf
开启子配置文件路径
[include]
files = /etc/supervisor/conf.d/*.conf
3./etc/supervisor/conf.d/ zqm.conf配置文件
[program:zqmxcx]
command = uwsgi --ini uwsgi.ini ;supervisor执行的命令
directory = /home/aaa ;项目的目录
process_name=%(program_name)s_%(process_num)02d
numprocs=1 ;进程数
autostart = true ;当supervisord启动,程序自动开始启动
autorestart = true ;程序挂了后自动重启
stdout_logfile = /home/aaa/supervisor.log ;输出的log文件
stderr_logfile = /home/aaa/supervisor_error.log ;输出的错误日志文件
startsecs=5 ;启动 5 秒后没有异常退出,就当作已经正常启动了
startretries=3 ;尝试重新启动次数
4.重启服务
systemctl restart supervisord
5.查看状态
[root@linux-node01 conf.d]# supervisorctl status
zqmxcx RUNNING pid 3182, uptime 0:01:00
此时如果你手动kill这个项目的pid,它就会实现重启