我想部署我的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激活。我剛剛做了什麼?除非在一次電話會議後這種情況不會持久?