V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
louzhumuyou
V2EX  ›  Python

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

  •  
  •   louzhumuyou · 2016-12-29 15:32:05 +08:00 · 3105 次点击
    这是一个创建于 2891 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    5 条回复    2016-12-29 23:13:25 +08:00
    xiuc001
        1
    xiuc001  
       2016-12-29 21:49:13 +08:00 via iPhone
    files 这个节点是用来加载配置的,你这个 python 文件是什么内容?一个配置文件写一个应用( program:app )
    xiuc001
        2
    xiuc001  
       2016-12-29 21:50:07 +08:00 via iPhone
    还有路径最好别用~,用绝对路径
    louzhumuyou
        3
    louzhumuyou  
    OP
       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
        4
    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
        5
    louzhumuyou  
    OP
       2016-12-29 23:13:25 +08:00
    @xiuc001 谢谢 我发现我自己搞定了 谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3476 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:47 · PVG 12:47 · LAX 20:47 · JFK 23:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.