nginx supervisor tornado运行django的问题

发布于 2021-11-16 21:33:13 字数 11716 浏览 897 评论 4

亲们,我用nginx supervisor tornado部署生产环境..

supervisor配置如下:

; Sample supervisor config file.

[unix_http_server]
;file=/tmp/supervisor.sock   ; (the path to the socket file)
file=/var/run/supervisor.sock
chmod=0777                 ; socket file mode (default 0700)
chown=root:jason       ; socket file uid:gid owner
;username=user              ; (default is no username (open server))
;password=123               ; (default is no password (open server))

[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)
pidfile=/var/run/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)
;umask=022                   ; (process file creation umask;default 022)
;user=chrism                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY=value       ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

; 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
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as http_username if set
;password=123                ; should be same as http_password if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.

;[program:theprogramname]
;command=/bin/cat              ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=999                  ; the relative start priority (default 999)
;autostart=true                ; start at supervisord start (default: true)
;autorestart=unexpected        ; whether/when to restart (default: unexpected)
;startsecs=1                   ; number of secs prog must stay running (def. 1)
;startretries=3                ; max # of serial start failures (default 3)
;exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;killasgroup=false             ; SIGKILL the UNIX process group (def false)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)
;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A=1,B=2           ; process environment additions (def no adds)
;serverurl=AUTO                ; override serverurl computation (childutils)

; The below sample eventlistener section shows all possible
; eventlistener subsection values, create one or more 'real'
; eventlistener: sections to be able to handle event notifications
; sent by supervisor.

;[eventlistener:theeventlistenername]
;command=/bin/eventlistener    ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;events=EVENT                  ; event notif. types to subscribe to (req'd)
;buffer_size=10                ; event buffer queue size (default 10)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=-1                   ; the relative start priority (default -1)
;autostart=true                ; start at supervisord start (default: true)
;autorestart=unexpected        ; whether/when to restart (default: unexpected)
;startsecs=1                   ; number of secs prog must stay running (def. 1)
;startretries=3                ; max # of serial start failures (default 3)
;exitcodes=0,2                 ; 'expected' exit codes for process (default 0,2)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;killasgroup=false             ; SIGKILL the UNIX process group (def false)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups        ; # of stderr logfile backups (default 10)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;environment=A=1,B=2           ; process environment additions
;serverurl=AUTO                ; override serverurl computation (childutils)

; The below sample group section shows all possible group values,
; create one or more 'real' group: sections to create "heterogeneous"
; process groups.
[group:ayapp]
programs= ay-web  ; each refers to 'x' in [program:x] definitions
;priority=999                  ; the relative start priority (default 999)

; 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 = relative/directory/*.ini

[program:ay-web]
command=python /var/www/aiyousite/Serv.py 80%(process_num)02d
process_name=%(program_name)s_%(process_num)02d
directory=/var/www/aiyousite
autostart=true
umask=022
startsecs=0
user=jason
stopwaitsecs=0
redirect_stderr=true
stdout_logfile=/tmp/ay_server-80%(process_num)02d.log
numprocs=4
numprocs_start=1

我写了一个基于Tornado的文件,用来启动如下:

  1 #tornado height combo connaction server by jason!
  2 import os
  3 import sys
  4 
  5 from tornado.options import options, define, parse_command_line
  6 import django.core.handlers.wsgi
  7 import tornado.httpserver
  8 import tornado.ioloop
  9 import tornado.web
 10 import tornado.wsgi
 11 
 12 _HERE = os.path.dirname(os.path.abspath(__file__))
 13 sys.path.append(_HERE)
 14 sys.path.append(os.path.join(_HERE, '..'))
 15 sys.path.append(os.path.join(_HERE, '../contrib'))
 16 os.environ['DJANGO_SETTINGS_MODULE'] = "aiyou.settings"
 17 
 18 def main(port):
 19     wsgi_app = tornado.wsgi.WSGIContainer(
 20         django.core.handlers.wsgi.WSGIHandler())
 21     tornado_app = tornado.web.Application(
 22         [('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
 23         ])
 24     server = tornado.httpserver.HTTPServer(tornado_app)
 25     server.listen(port)
 26     tornado.ioloop.IOLoop.instance().start()
 27 
 28 if __name__ == '__main__':
 29     main(int(sys.argv[1]))

这样的话,运行的时候,会有500错误。

我看了以下日志,报的错误如下:

 

Traceback (most recent call last):
  File "/var/www/aiyousite/Serv.py", line 29, in <module>
    main(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: '-port=8001'
Traceback (most recent call last):
  File "/var/www/aiyousite/Serv.py", line 29, in <module>
    main(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: '-port=8001'
Traceback (most recent call last):
  File "/var/www/aiyousite/Serv.py", line 29, in <module>
    main(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: '-port=8001'
Traceback (most recent call last):
  File "/var/www/aiyousite/Serv.py", line 29, in <module>
    main(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: '-port=8001'
Traceback (most recent call last):
  File "/var/www/aiyousite/Serv.py", line 29, in <module>
    main(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: '-port=8001'
Traceback (most recent call last):
  File "/var/www/aiyousite/Serv.py", line 29, in <module>
    main(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: '-port=8001'
Traceback (most recent call last):
  File "/var/www/aiyousite/Serv.py", line 29, in <module>
    main(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: '-port=8001'
Traceback (most recent call last):
  File "/var/www/aiyousite/Serv.py", line 29, in <module>
    main(int(sys.argv[1]))
ValueError: invalid literal for int() with base 10: '-port=8001'

看了一下应该是我在supervisor里的设置,实际传给Serv.py的端口不是int类型的参数

而是-port=8001

可是

command=python /var/www/aiyousite/Serv.py 80%(process_num)02d
;这里我并没有写成 

command=python /var/www/aiyousite/Serv.py -port=80%(process_num)02d

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北笙凉宸 2021-11-16 23:01:44

新配置文件貌似没生效, 修改supervisor的配置文件后执行supervisorctl reload xxxx了么

霞映澄塘 2021-11-16 23:01:25

或者直接解析str

猫烠⑼条掵仅有一顆心 2021-11-16 23:01:20
if __name__ == '__main__':
冷清清 2021-11-16 22:54:16

现在访问网站的话,出现500: Internal Server Error

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文