supervisor 总是报错,不知能否求助一下

2016-12-29 15:32:05 +08:00
 louzhumuyou

我的 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
                      

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

3037 次点击
所在节点    Python
5 条回复
xiuc001
2016-12-29 21:49:13 +08:00
files 这个节点是用来加载配置的,你这个 python 文件是什么内容?一个配置文件写一个应用( program:app )
xiuc001
2016-12-29 21:50:07 +08:00
还有路径最好别用~,用绝对路径
louzhumuyou
2016-12-29 22:07:39 +08:00
@xiuc001 我这里的 python 文件内容是
```
#coding=utf-8
from __future__ import with_statement
from app import create_app


application = create_app()
if __name__ == "__main__":
application.run()
```
xiuc001
2016-12-29 22:33:36 +08:00
你把下面这段放到一个文件里面
[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

然后 file 这个 section 包含这个文件所在的目录
再重启 supervisord 就好了
你在命令行执行 echo_supervisord_conf ,看看 files 的例子就知道了
louzhumuyou
2016-12-29 23:13:25 +08:00
@xiuc001 谢谢 我发现我自己搞定了 谢谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/331017

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX