django + gunicorn + supervisor
在服务器上跑着一个Django项目,想用supervisor管理起来,遇到一个小问题,记录一下
本来启动Django项目的命令是用的manage.py , 但是这中方法有个很神奇的坑,就是ctrl + c 终止程序后,端口号还被占用,年少无知的我以为都是这样,偶尔用gunicorn启动了一次,发现人家就没这毛病,顿时感觉好蠢
所以,接下来就是用gunicorn来启动Django项目了, 对于Django项目来说,有一个自带的wsgi.py文件,我们用这个文件来启动就行 ,
在命令行的名令是:(执行命令的路径是在manage.py所在的目录)
gunicorn appproject.wsgi:application -b 0.0.0.0:8080 # appproject是项目名
这就是最基本的启动命令, 第一次用可能会对 ` appproject.wsgi:application ` 觉得奇怪,其实没什么,appproject.wsgi 实际上就是appproject/wsgi , 然后你打开这个wsgi文件,就知道application是怎么回事了
如果你用gunicorn启动的是一个flask项目,那个写法就一目了然了
重点是gunicorn启动项目,就得这么启动,必须有个启动文件
还有坑就是,只能用点的方式去引用,不要用路径的方式,那种会报错 ` ImportError: Import by filename is not supported. `
好了,下面说一下supervisor的用法:
基本用法从网上一搜一大把,我就不复制了,就说一下添加一个进程该写哪些东西,就以上面这个项目为例,比如我们现在要添加对这个项目的管理
1. 一般supervisor的配置目录都在 /etc/supervisor/ 下
进到这个目录, 打开supervisior.conf文件,注意这个文件中的最下面的include, 这个是supervisor配置的要管理的项目的配置,到这个目录下去添加一个配置
; supervisor config file [unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod= ; sockef file mode (default ) [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 , 刚才应该也看到了
2. 好了,现在进入这个目录
如果supervisor已经在管理着其他进程, 这里面应该已经有一些.conf文件了, 可以参照这些文件, 比如添加一个test.conf, 里面的内容:
[program:slots_console] # 项目名
autorestart=True # 项目挂掉后是否自动重启
redirect_stderr=True # 自动记错误日志
command=/mnt/slots_spin/lib/slots_admin/venv/bin/gunicorn -b 0.0.0.0: slots_console_backend.wsgi:application # 这个是重点,启动命令, 格式是 gunicorn [参数] application 顺序不要写反, 而且application不要写一长串路径,不要担心找不到文件,目录在下面写
user=ubuntu
autostart=True
directory=/mnt/slots_spin/lib/slots_admin/slots_console/slots_console_backend # 这个是启动命令的执行目录
3. 配置好后, ` sudo supervisorctl `,进入supervisor的管理界面,首先用update命令更新一下配置,然后用status查看一下状态,不出意外已经启动起来了,如果有问题,去看日志,日志文件目录在` supervisior.conf `文件里有写
django + gunicorn + supervisor的更多相关文章
- django+nginx+supervisor+gunicorn+gevent 网站部署
django+nginx+supervisor+gunicorn+gevent 网站部署 django,nginx,supervisor,gunicorn,gevent这几个都是在本领域大名鼎鼎的软件 ...
- Centos7 + Python3.6 + Django + virtualenv + gunicorn + supervisor 环境配置详解
跟着网上的教程走发现行不通阿!好多都是写个大概,而且每人的环境都是有些许差异的,比如说权限问题阿,等等都会造成安装的失败 说明:本教程在你已经拥有Centos7系统,已经安装好nginx服务器,已经安 ...
- nginx+uWSGI+django+virtualenv+supervisor发布web服务器
nginx+uWSGI+django+virtualenv+supervisor发布web服务器 导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以 ...
- 12,nginx+uWSGI+django+virtualenv+supervisor发布web服务器
导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以及Web应用程序如何链接在一起以处理一个请求,(接收请求,处理请求,响应请求) 基于wsgi运行的框架 ...
- nginx+uWSGI+django+virtualenv+supervisor发布web服务器流程
导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以及Web应用程序如何链接在一起以处理一个请求,(接收请求,处理请求,响应请求)基于wsgi运行的框架有 ...
- virtualenv 环境下 Nginx + Flask + Gunicorn+ Supervisor 搭建 Python Web
在这篇文章里,我们将搭建一个简单的 Web 应用,在虚拟环境中基于 Flask 框架,用 Gunicorn 做 wsgi 容器,用 Supervisor 管理进程,然后使用 Python 探针来监测应 ...
- flask +gevent+nginx+Gunicorn+supervisor部署flask应用
上篇 可以完美部署flask ,但是视乎在结合gevent+apscheduler 实现异步非阻塞后台和定时任务的时候视乎不是那么完美.请教了前辈,决定使用flask+gevent+nginx+g ...
- 腾讯云Unubtu 16.04 (gunicorn+supervisor+ngnix+mongodb)部署Flask应用
1.申请腾讯云服务 我申请了免费使用的云服务器 ,选择安装的Linux版本是ubuntu16.04.1 LTSx86_64.我个人PC安装使用的也是这个版本,比较熟悉些. 详细参考帮助文档. 2.登录 ...
- 初次部署django+gunicorn+nginx
初次部署django+gunicorn+nginx 博客详细地址 https://www.cnblogs.com/nanrou/p/7026802.html 写在前面,这只是我所遇到的情况,如果有 ...
随机推荐
- 绘制字符串:imagestring()
<?php //1. 绘制图像资源(创建一个画布) $image = imagecreatetruecolor(500, 300); //2. 先分配一个绿色 $green = imagecol ...
- 数据结构-队列(Queue)
#include <stdio.h> #include <stdlib.h> #define LIST_INIT_SIZE 10 #define LISTINCREMENT 1 ...
- opencv使用日记之一:平台搭建Mat类以及图像的读取修改
平台搭建就摸了一整天时间,真的是...不说了,最后我选择的是 opencv3.0(2015/06/04) + win7 + vs2012 注意opencv的版本不同导入的库文件是不一样的,所以请 ...
- excel VBA 将文本数值转换为数字格式(单元格中数据左上角是绿三角,鼠标点上有叹号标示)
Range("A6").SelectSelection.CopyRange("A10:A60").SelectRange(Selection, Selectio ...
- UVa 1649 Binomial coefficients 数学
题意: \(C(n, k) = m(2 \leq m \leq 10^{15})\),给出\(m\)求所有可能的\(n\)和\(k\). 分析: 设\(minK = min(k, n - k)\),容 ...
- Redis实现之复制(一)
复制 在Redis中,用户可以通过执行SLAVEOF命令或者设置slaveof选项,让一个服务器去复制(replicate)另一个服务器,我们称呼被复制的服务器为主服务器(master),而对主服务器 ...
- Python虚拟机类机制之descriptor(三)
从slot到descriptor 在Python虚拟机类机制之填充tp_dict(二)这一章的末尾,我们介绍了slot,slot包含了很多关于一个操作的信息,但是很可惜,在tp_dict中,与__ge ...
- Python抓取视频内容
Python抓取视频内容 Python 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年.Python语法简洁而清晰,具 ...
- windows服务自动备份数据库
最近写了几个windows服务用于自动备份与删除数据: services代码如下: public partial class Service1 : ServiceBase { public Servi ...
- Python+Selenium练习篇之15-在浏览器中新开一个tab
本文介绍如selenium方法打开一个新的tab,我们知道在浏览器里,我们按住 ctrl+ t 就可以新打开一个tab.所以我们学习如何利用webdriver中send_key 的方法去触发ctrl+ ...