2016-12-19 1 views
1

내 Django 앱을 사용하여 AWS Elastic Beanstalk에서 셀러리를 실행하고 싶습니다. 나는 @yellowcap (How do you run a worker with AWS Elastic Beanstalk?)의 위대한 대답을 따랐다. 그래서 내 supervisord.conf은 다음과 같습니다 : 내 탄성 콩 줄기 환경 특성에 내 settings.py에 있던 몇 가지 변수를 마이그레이션하기로 결정할 때까지환경 변수를 사용하여 AWS Elastic Beanstalk에서 django로 셀러리를 실행하십시오.

files: 
"/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh": 
mode: "000755" 
owner: root 
group: root 
content: | 
    #!/usr/bin/env bash 

    # Get django environment variables 
    celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'` 
    celeryenv=${celeryenv%?} 

    # Create celery configuraiton script 
    celeryconf="[program:celeryd] 
    ; Set full path to celery program if using virtualenv 
    command=/opt/python/run/venv/bin/celery worker -A myappname --loglevel=INFO 

    directory=/opt/python/current/app 
    user=nobody 
    numprocs=1 
    stdout_logfile=/var/log/celery-worker.log 
    stderr_logfile=/var/log/celery-worker.log 
    autostart=true 
    autorestart=true 
    startsecs=10 

    ; Need to wait for currently executing tasks to finish at shutdown. 
    ; Increase this if you have very long running tasks. 
    stopwaitsecs = 600 

    ; When resorting to send SIGKILL to the program to terminate it 
    ; send SIGKILL to its whole process group instead, 
    ; taking care of its children as well. 
    killasgroup=true 

    ; if rabbitmq is supervised, set its priority higher 
    ; so it starts first 
    priority=998 

    environment=$celeryenv" 

    # Create the celery supervisord conf script 
    echo "$celeryconf" | tee /opt/python/etc/celery.conf 

    # Add configuration script to supervisord conf (if not there already) 
    if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf 
     then 
     echo "[include]" | tee -a /opt/python/etc/supervisord.conf 
     echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf 
    fi 

    # Reread the supervisord config 
    supervisorctl -c /opt/python/etc/supervisord.conf reread 

    # Update supervisord in cache without restarting all services 
    supervisorctl -c /opt/python/etc/supervisord.conf update 

    # Start/Restart celeryd through supervisord 
    supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd 

그의 코드는 괜찮 았는데. 도움을

for \'environment\' is badly formatted'>: file: /usr/lib64/python2.7/xmlrpclib.py line: 800 
celeryd: ERROR (no such process) 

감사 :

사실, 나는 스크립트가 호출 될 때 다음과 같은 오류가 있습니다.

+0

사용자 환경 라인이있다 후행 따옴표. 그게 거기에 있어야합니까? 'environment = $ celeryenv "' – 2ps

+0

네, 셀러리의 선언이 끝났습니다 –

+0

생성 된 celery.conf를 붙여 넣기를 할 수 있습니까? – 2ps

답변

1

이것은 Supervisor가 구성 파일을 구문 분석하는 방법 때문입니다 [1].

환경 설정에 이스케이프 처리되지 않은 % 문자가 포함되어 있습니다. 아마도 Django SECRET_KEY에서 가져온 것입니다.

다음은 나를 위해 일한

- 여기 파이프 체인 | sed 's/%/%%/g'를 추가하려고 :

celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'`

결과 라인 :

celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g' | sed 's/%/%%/g'`

[1] https://github.com/Supervisor/supervisor/issues/291