【问题标题】:Supervisord can't start Tornado serverSupervisord 无法启动 Tornado 服务器
【发布时间】:2012-09-08 19:45:46
【问题描述】:

我花了 6 个小时试图找出它为什么不起作用。真的不知道为什么。提前致谢!

注意:以下设置在 ubuntu 服务器上完美运行,但在我的本地 MacOSX 上失败

这是我的 supervisord.conf:

;local conf

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

[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=debug                ; (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:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

[include]
files = conf.d/*.conf

这是我的 conf.d 文件夹下的 tornado.conf:

[group:tornadoes]
programs=tornado-8000,tornado-8001,tornado-8002,tornado-8003

[program:tornado-8000]
command=python /Users/horace/server/server.py --port=8000
directory=/var/www
user=www-data
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado.log
loglevel=info

[program:tornado-8001]
command=python /Users/horace/server/server.py --port=8001
directory=/var/www
user=www-data
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado.log
loglevel=info

[program:tornado-8002]
command=python /Users/horace/server/server.py --port=8002
directory=/var/www
user=www-data
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado.log
loglevel=info

[program:tornado-8003]
command=python /Users/horace/server/server.py --port=8003
directory=/var/www
user=www-data
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/tornado.log
loglevel=info

运行后

sudo supervisord -n -edebug

我得到了这些日志。

注意:我看到了“ImportError: No module named tornado.httpserver”错误。但是当我尝试从带有“

的文件夹中运行 server.py
python server.py --port=8000

服务器启动没有任何问题。为什么supervisord无法启动它,这让我很困惑。

/Library/Python/2.7/site-packages/supervisor/options.py:286: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
2012-09-16 14:29:40,866 CRIT Supervisor running as root (no user in config file)
2012-09-16 14:29:40,866 WARN Included extra file "/Users/horace/supervisor/conf.d/tornado.conf" during parsing
2012-09-16 14:29:40,866 INFO Increased RLIMIT_NOFILE limit to 1024
2012-09-16 14:29:40,889 INFO RPC interface 'supervisor' initialized
2012-09-16 14:29:40,889 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2012-09-16 14:29:40,889 INFO supervisord started with pid 6367
2012-09-16 14:29:41,895 INFO spawned: 'tornado-8000' with pid 6370
2012-09-16 14:29:41,897 INFO spawned: 'tornado-8001' with pid 6371
2012-09-16 14:29:41,899 INFO spawned: 'tornado-8002' with pid 6372
2012-09-16 14:29:41,902 INFO spawned: 'tornado-8003' with pid 6373
2012-09-16 14:29:41,915 DEBG 'tornado-8000' stdout output:
supervisor: error trying to setuid to 0 (Could not set groups of effective user)

2012-09-16 14:29:41,915 DEBG 'tornado-8001' stdout output:
supervisor: error trying to setuid to 0 (Could not set groups of effective user)

2012-09-16 14:29:41,917 DEBG 'tornado-8002' stdout output:
supervisor: error trying to setuid to 0 (Could not set groups of effective user)

2012-09-16 14:29:41,919 DEBG 'tornado-8003' stdout output:
supervisor: error trying to setuid to 0 (Could not set groups of effective user)

2012-09-16 14:29:41,974 DEBG 'tornado-8000' stdout output:
Traceback (most recent call last):
  File "/Users/horace/server/server.py", line 4, in <module>
    import tornado.httpserver
ImportError: No module named tornado.httpserver

2012-09-16 14:29:41,974 DEBG 'tornado-8001' stdout output:
Traceback (most recent call last):
  File "/Users/horace/server/server.py", line 4, in <module>
    import tornado.httpserver
ImportError: No module named tornado.httpserver

2012-09-16 14:29:41,974 DEBG 'tornado-8002' stdout output:
Traceback (most recent call last):
  File "/Users/horace/server/server.py", line 4, in <module>
    import tornado.httpserver
ImportError: No module named tornado.httpserver

2012-09-16 14:29:41,974 DEBG 'tornado-8003' stdout output:
Traceback (most recent call last):
  File "/Users/horace/server/server.py", line 4, in <module>
    import tornado.httpserver
ImportError: No module named tornado.httpserver



2012-09-16 14:29:48,133 DEBG fd 10 closed, stopped monitoring <POutputDispatcher at 4345929384 for <Subprocess at 4345718256 with name tornado-8001 in state STARTING> (stdout)>
2012-09-16 14:29:48,133 INFO exited: tornado-8001 (exit status 1; not expected)
2012-09-16 14:29:48,133 DEBG fd 7 closed, stopped monitoring <POutputDispatcher at 4345929312 for <Subprocess at 4345718112 with name tornado-8000 in state STARTING> (stdout)>
2012-09-16 14:29:48,133 INFO exited: tornado-8000 (exit status 1; not expected)
2012-09-16 14:29:48,133 DEBG received SIGCHLD indicating a child quit
2012-09-16 14:29:48,135 DEBG 'tornado-8002' stdout output:
Traceback (most recent call last):
  File "/Users/horace/server/server.py", line 4, in <module>
    import tornado.httpserver
ImportError: No module named tornado.httpserver

2012-09-16 14:29:48,136 DEBG 'tornado-8003' stdout output:
Traceback (most recent call last):
  File "/Users/horace/server/server.py", line 4, in <module>
    import tornado.httpserver
ImportError: No module named tornado.httpserver

2012-09-16 14:29:48,136 INFO gave up: tornado-8000 entered FATAL state, too many start retries too quickly
2012-09-16 14:29:48,136 INFO gave up: tornado-8001 entered FATAL state, too many start retries too quickly
2012-09-16 14:29:48,137 DEBG fd 14 closed, stopped monitoring <POutputDispatcher at 4346496280 for <Subprocess at 4345718400 with name tornado-8003 in state STARTING> (stdout)>
2012-09-16 14:29:48,137 INFO exited: tornado-8003 (exit status 1; not expected)
2012-09-16 14:29:48,137 DEBG fd 12 closed, stopped monitoring <POutputDispatcher at 4346495200 for <Subprocess at 4345718328 with name tornado-8002 in state STARTING> (stdout)>
2012-09-16 14:29:48,137 INFO exited: tornado-8002 (exit status 1; not expected)
2012-09-16 14:29:48,137 DEBG received SIGCHLD indicating a child quit
2012-09-16 14:29:49,139 INFO gave up: tornado-8002 entered FATAL state, too many start retries too quickly
2012-09-16 14:29:49,139 INFO gave up: tornado-8003 entered FATAL state, too many start retries too quickly

更新:我不知道为什么,但我通过以下方式启动了服务器:

su root

然后启动supervisord。一切运行正常。 但是还是不知道为什么在我的普通用户horace下,我无法启动它。 (导入 tornado.httpserver 模块)

sudo supervisord

有人知道原因吗?谢谢。

【问题讨论】:

  • tornado 在你的全局 python 路径中吗?还是只是在您应用的文件夹中?
  • users/Horace/server 文件夹中有tornado 文件夹吗?
  • 是的。我在服务器文件夹下拥有所有的 tornado server.py 文件。我可以手动启动它
  • @horacex: 你可以手动启动它作为用户 www-data 吗?
  • 我可以。使用相同的命令:python server.py --port=8000.

标签: python macos tornado supervisord


【解决方案1】:

您是否尝试设置environment=PYTHONPATH="..." 变量?

编辑:

supervisor.conf:

[include]
files = *.supervisor

[supervisord]

[supervisorctl]
serverurl = unix://supervisord.sock

[unix_http_server]
file = supervisord.sock

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

app1.supervisor:

[program:app1]
process_name = app1-%(process_num)s
environment = PYTHONPATH="%(here)s/apps/env/current"
command = python -m apps.app1 --port=%(process_num)s
#--log_file_prefix=app.log                                                                                  
# Increase numprocs to run multiple processes on different ports.                                                   
# Note that the chat demo won't actually work in that configuration                                                 
# because it assumes all listeners are in one process.                                                              
numprocs = 2
numprocs_start = 8000

【讨论】:

    【解决方案2】:

    您的 supervisord 配置文件看起来不错。

    对我来说缺少的是在服务器上的 virtualenv 中运行主管。

    我在运行 supervisord -c my_conf_file 之前添加了 virtualenv source mydir/bin/activate 行,这很有效。

    【讨论】:

      猜你喜欢
      • 2019-05-16
      • 2019-03-28
      • 2019-07-20
      • 2011-08-05
      • 1970-01-01
      • 2013-12-08
      • 2015-08-15
      • 2021-07-08
      • 2013-06-05
      相关资源
      最近更新 更多