在服务器上跑着一个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的更多相关文章

  1. django+nginx+supervisor+gunicorn+gevent 网站部署

    django+nginx+supervisor+gunicorn+gevent 网站部署 django,nginx,supervisor,gunicorn,gevent这几个都是在本领域大名鼎鼎的软件 ...

  2. Centos7 + Python3.6 + Django + virtualenv + gunicorn + supervisor 环境配置详解

    跟着网上的教程走发现行不通阿!好多都是写个大概,而且每人的环境都是有些许差异的,比如说权限问题阿,等等都会造成安装的失败 说明:本教程在你已经拥有Centos7系统,已经安装好nginx服务器,已经安 ...

  3. nginx+uWSGI+django+virtualenv+supervisor发布web服务器

    nginx+uWSGI+django+virtualenv+supervisor发布web服务器   导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以 ...

  4. 12,nginx+uWSGI+django+virtualenv+supervisor发布web服务器

    导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以及Web应用程序如何链接在一起以处理一个请求,(接收请求,处理请求,响应请求) 基于wsgi运行的框架 ...

  5. nginx+uWSGI+django+virtualenv+supervisor发布web服务器流程

    导论 WSGI是Web服务器网关接口.它是一个规范,描述了Web服务器如何与Web应用程序通信,以及Web应用程序如何链接在一起以处理一个请求,(接收请求,处理请求,响应请求)基于wsgi运行的框架有 ...

  6. virtualenv 环境下 Nginx + Flask + Gunicorn+ Supervisor 搭建 Python Web

    在这篇文章里,我们将搭建一个简单的 Web 应用,在虚拟环境中基于 Flask 框架,用 Gunicorn 做 wsgi 容器,用 Supervisor 管理进程,然后使用 Python 探针来监测应 ...

  7. flask +gevent+nginx+Gunicorn+supervisor部署flask应用

    上篇   可以完美部署flask ,但是视乎在结合gevent+apscheduler 实现异步非阻塞后台和定时任务的时候视乎不是那么完美.请教了前辈,决定使用flask+gevent+nginx+g ...

  8. 腾讯云Unubtu 16.04 (gunicorn+supervisor+ngnix+mongodb)部署Flask应用

    1.申请腾讯云服务 我申请了免费使用的云服务器 ,选择安装的Linux版本是ubuntu16.04.1 LTSx86_64.我个人PC安装使用的也是这个版本,比较熟悉些. 详细参考帮助文档. 2.登录 ...

  9. 初次部署django+gunicorn+nginx

    初次部署django+gunicorn+nginx  博客详细地址  https://www.cnblogs.com/nanrou/p/7026802.html 写在前面,这只是我所遇到的情况,如果有 ...

随机推荐

  1. psutil——获取系统信息的Python第三方模块

    本文摘自廖雪峰大神个人网站:https://www.liaoxuefeng.com/wiki/1016959663602400/1183565811281984 用Python来编写脚本简化日常的运维 ...

  2. 各种友(e)善(xin)数论总集(未完待续),从入门到绝望

    目录 快速幂 扩展欧几里得 GCD 扩展欧几里得 同余系列 同余方程 同余方程组 一点想法 高次同余方程 BSGS exBSGS 线性筛素数 埃式筛 欧拉筛 欧拉函数 讲解 两道水题 法雷级数 可见点 ...

  3. A1046 Shortest Distance (20)(20 分)

    1046 Shortest Distance (20)(20 分)提问 The task is really simple: given N exits on a highway which form ...

  4. 处理IE6下PNG图片透明背景问题

    由于历史原因,IE较早的版本不支持PNG透明 可以支持GIF等的透明 由于png图片相对较小,所以很多网站还是青睐于PNG图片 最近就遇到这种情况,使用js和css滤镜来实现的与大家分享一下下: 首先 ...

  5. Service IntentService区别 (面试)

    依然记得自己当初没有真正的工作经验的时候的日子,满北京跑,没有人要.妈的,现在就想问,还有谁!想想真解气.不提了. 曾经有个面试官问我service 和IntentService的区别.当时自己模模糊 ...

  6. 9、JS对象 知识总结

    1.对象 <!DOCTYPE html> <html> <body> <script> <!-- 新建对象 --> person=new O ...

  7. Robotium测试报告的生成方法(上)

    7.1 使用junit-report生成报告 这个是参考网上的:http://www.xuebuyuan.com/2148574.html,经我个人验证是可行的方法,网上写的挺详细的,不过有些不太清楚 ...

  8. Java学习之字符串类

    String在Java中是一个类类型(非主类型),是一个不可被继承的final类,而且字符串对象是一个不可变对象.声明的String对象应该被分配到堆中,声明的变量名应该持有的是String对象的引用 ...

  9. nyoj 题目17 单调递增最长子序列

    单调递增最长子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 求一个字符串的最长递增子序列的长度如:dabdbf最长递增子序列就是abdf,长度为4   输入 ...

  10. AngularJs 特性 之 指令系统

    <!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="utf- ...