原因

我在 V2EX 发了求助帖,好像没有人回复,我在 testerhome 碰碰运气吧,简述一下问题。
我需要部署 flask 写的小应用,之前一直用 gunicorn 部署的,但是每次需要重启感觉麻烦,然后知道 supervisor 可以守护进程加上 gunicorn 执行,但是我遇到了问题。

我的 supervisor.conf 如下:

; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)

[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))

[supervisord]
logfile=/tmp/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)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/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=user              ; should be same as http_username if set
password=123                ; should be same as http_password if set


[include]
files =ci_ios/webhook/wsgi.py
[program:wsgi]
command=~/Documents/supervisor/env/bin/gunicorn --chdir ~/Documents/supervisor
/ci_ios/webhook -b 0.0.0.0:8000 wsgi:application
startsecs=0                                                                             
stopwaitsecs=0                                                                         
autostart=false                                                                         
autorestart=true                                                                       
stdout_logfile=/tmp/gunicorn.log                         
stderr_logfile=/tmp/gunicorn.err 

然后我直接启动命令,
~/Documents/supervisor/env/bin/gunicorn --chdir ~/Documents/supervisor/ci_ios/webhook -b 0.0.0.0:8000 wsgi:application, 没有报错,可以正常启动:

 Starting gunicorn 19.6.0
[2016-12-29 15:23:45 +0800] [35578] [INFO] Listening at: http://0.0.0.0:8000 (35578)
[2016-12-29 15:23:45 +0800] [35578] [INFO] Using worker: sync
[2016-12-29 15:23:45 +0800] [35581] [INFO] Booting worker with pid: 35581
^C[2016-12-29 15:23:54 +0800] [35578] [INFO] Handling signal: int
[2016-12-29 15:23:54 +0800] [35581] [INFO] Worker exiting (pid: 35581)

但是我通过supervisord -c supervisor.conf就会报错:

Error: File contains no section headers.
file: /Users/djx/Documents/supervisor/ci_ios/webhook/wsgi.py, line: 2
'from __future__ import with_statement\n'
For help, use /Users/djx/Documents/supervisor/env/bin/supervisord -h

可是谷歌了半天也不知到底该怎么改,我保存的 py 格式是 UTF-8 无 BOM 。

还有我的项目目录的结构是

~/Documents/supervisor/

                  ci_ios/webhook/wsgi.py

                      supervisor.conf

希望大神赶快出现,我实在无力解决。

我对这方面了解可能不足,或许我的 supervisor.conf 写的有问题,希望可以告诉我指导一下。

谢谢。


↙↙↙阅读原文可查看相关链接,并与作者交流