我正在尝试使用supervisor来管理Daphne服务器以及AWS中Django应用程序的一些工作者。我一直关注this tutorial。我的supervisord.conf
看起来像这样:
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0770 ; socket file mode (default 0700)
chown=root:supervisor
[inet_http_server]
port = 9001
username = nte_user # Basic auth username
password = generated-passphrase # Basic auth password
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; 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
; 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 = /etc/supervisor/conf.d/*.conf
我的自定义配置文件位于/etc/supervisor/conf.d/company_name.conf
,看起来像这样(我在添加工作人员之前试图让server_interface
正常工作):
[program:server_interface]
command=/home/web/venv/bin/daphne -b 127.0.0.1 -p 8000 company_name.asgi:channel_layer
directory=/home/web/api-server/company_name/
autostart=true
autorestart=true
stopasgroup=true
user=web
当我在/home/web/venv/bin/daphne -b 127.0.0.1 -p 8000 company_name.asgi:channel_layer
中从命令行运行此命令:/home/web/api-server/company_name/
时,它运行正常,服务器启动。当我运行supervisorctl start server_interface
时,我在sdterr日志中看到了这个输出:
2017-07-07 15:46:06,562 INFO Starting new HTTP connection (1): 169.254.169.254
Traceback (most recent call last):
File "/home/web/venv/bin/daphne", line 11, in <module>
sys.exit(CommandLineInterface.entrypoint())
File "/home/web/venv/local/lib/python2.7/site-packages/daphne/cli.py", line 125, in entrypoint
cls().run(sys.argv[1:])
File "/home/web/venv/local/lib/python2.7/site-packages/daphne/cli.py", line 155, in run
channel_layer = importlib.import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "./next-tier/asgi.py", line 6, in <module>
channel_layer = get_channel_layer()
File "/home/web/venv/local/lib/python2.7/site-packages/channels/asgi.py", line 98, in get_channel_layer
django.setup(set_prefix=False)
File "/home/web/venv/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/web/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/web/venv/local/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "./stakeholder/models.py", line 18, in <module>
from .managers import StakeholderManager, ContactInformationManager
File "./stakeholder/managers.py", line 27, in <module>
SURVEY_TABLE = DYNAMO_DB.Table(settings.SURVEY_TABLE_NAME)
File "/home/web/venv/local/lib/python2.7/site-packages/boto3/resources/factory.py", line 474, in create_resource
client=self.meta.client)(*args, **kwargs)
File "/home/web/venv/local/lib/python2.7/site-packages/boto3/dynamodb/transform.py", line 32, in __init__
super(DynamoDBHighLevelResource, self).__init__(*args, **kwargs)
File "/home/web/venv/local/lib/python2.7/site-packages/boto3/dynamodb/table.py", line 30, in __init__
super(TableResource, self).__init__(*args, **kwargs)
File "/home/web/venv/local/lib/python2.7/site-packages/boto3/resources/base.py", line 119, in __init__
'Required parameter {0} not set'.format(identifier))
ValueError: Required parameter name not set
运行printenv
显示必需的环境变量set,这是由Daphne从命令行正常启动的事实证实的,但我无法弄清楚为什么它在运行时不能正确启动主管。