我想部署我的Django渠道应用程序到弹性beanstalk并启动达芙妮和工作部署我有一个supervisord脚本,在部署过程中被复制和重新启动。一些奇怪的行为正在发生如下详述。Virtualenv没有被从supervisord AWS Elasticbeanstalk激活
这是被部署在运行我channels.config文件
container_commands:
01_copy_supervisord_conf:
command: "cp .ebextensions/supervisord/supervisord.conf /opt/python/etc/supervisord.conf"
02_reload_supervisord:
command: "supervisorctl -c /opt/python/etc/supervisord.conf reload"
当我只有这个在我supervisord.conf
[unix_http_server]
file=/opt/python/run/supervisor.sock ; (the path to the socket file)
;chmod=0700 ; socket file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
[supervisord]
logfile=/opt/python/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=10MB ; (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=/opt/python/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
directory=/opt/python/current/app ; (default is not to cd during start)
;nocleanup=true ; (don't clean up tempfiles at start;default false)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///opt/python/run/supervisor.sock
[program:httpd]
command=/opt/python/bin/httpdlaunch
numprocs=1
directory=/opt/python/current/app
autostart=true
autorestart=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)
killasgroup=false ; SIGKILL the UNIX process group (def false)
redirect_stderr=false
的EB部署罚款(尽管达芙妮和工人没有启动和运行)
如果我把这个添加到我的supervisord.conf文件中:
[program:Daphne]
environment=PATH="/opt/python/run/venv/bin"
command=/opt/python/run/venv/bin/daphne -b 0.0.0.0 -p 5000 chat.asgi:channel_layer
directory=/opt/python/current/app
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/daphne.out.log
然后部署失败,此错误:
error: , : file: /usr/lib64/python2.7/xmlrpclib.py line: 800
Traceback (most recent call last):
File "/opt/elasticbeanstalk/hooks/appdeploy/enact/01flip.py", line 42, in
main()
File "/opt/elasticbeanstalk/hooks/appdeploy/enact/01flip.py", line 36, in main
config.restart_apache()
File "/opt/elasticbeanstalk/hooks/config.py", line 250, in restart_apache
apache_cmd('restart', should_be_running=True)
File "/opt/elasticbeanstalk/hooks/config.py", line 254, in apache_cmd
check_call('/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf %s httpd' % command, shell=True)
File "/usr/lib64/python2.7/subprocess.py", line 541, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf restart httpd' returned non-zero exit status 2.
,但如果我使用SSH连接实例比PS -aux |少了我可以看到达芙妮实际上在跑步。
然后,如果我加入到这个supervisord.conf:
[program:Worker]
environment=PATH="/opt/python/run/venv/bin"
command=python manage.py runworker
directory=/opt/python/current/app
process_name=%(program_name)s_%(process_num)02d
numprocs=4
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/workers.out.log
再次失败,相同的错误部署,但是当我检查workers.out.log日志,我看到
Traceback (most recent call last):
File "manage.py", line 17, in <module>
"Couldn't import Django. Are you sure it's installed and "
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
这意味着它不使用Worker程序的环境部分?
不知道哪里出错了。我尝试过四处看看如何通过supervisord激活virtualenv,但想出我正在做的事情。
编辑1 所以我能够解决它未能通过包括这在我的项目中的shell脚本部署部署问题:
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
,这在我的supervisord.conf文件:
[program:runvenv]
command=sh virtualenv-sh /opt/python/run/venv
directory=/opt/python/current/app
stdout_logfile=/tmp/venv.out.log
它成功地部署,达芙妮仍然在运行,但是当我检查worker.out.log文件时,它仍然给了我关于Django的相同的错误没有被安装,并确保我有六rtualenv激活。我刚刚做了什么?除非在一次电话会议后这种情况不会持久?