2015-03-23 17 views
8

Sto tentando di eseguire celerybeat come un demone in beanstalk elastico. Ecco il mio file di configurazione:Daemonize Celerybeat in Elastic Beanstalk (AWS)

files: 
"/opt/python/log/django.log": 
mode: "000666" 
owner: ec2-user 
group: ec2-user 
content: | 
    # Log file 
encoding: plain 
"/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/%/%%/g' | 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 avtotest --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 celerybeat configuraiton script 
    celerybeatconf="[program:celerybeat] 
    ; Set full path to celery program if using virtualenv 
    command=/opt/python/run/venv/bin/celery beat -A avtotest --loglevel=INFO 

    ; remove the -A avtotest argument if you are not using an app instance 

    directory=/opt/python/current/app 
    user=nobody 
    numprocs=1 
    stdout_logfile=/var/log/celerybeat.log 
    stderr_logfile=/var/log/celerybeat.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=999 

    environment=$celeryenv" 

    # Create the celery and beat supervisord conf script 
    echo "$celeryconf" | tee /opt/python/etc/celery.conf 
    echo "$celerybeatconf" | tee /opt/python/etc/celerybeat.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 
     echo "files: celerybeat.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 

Questo file demonizza sia il sedano che il sedano. Il sedano sta funzionando bene. Ma il sedano non lo è. Non vedo il file celerybeat.log creato che penso suggerisca che il celerybeat non funzioni.

Qualche idea al riguardo?

Inserirò altro codice se necessario. Grazie per l'aiuto

+1

Si dovrebbe riavviare anche 'celerybeat' nell'ultima riga della sceneggiatura? – pztrick

risposta

3

La sintassi di supervisord è un po 'spenta, prima di tutto potresti aver bisogno di SSH nell'istanza e modificare direttamente il file supervisord.conf (vim /opt/python/etc/supervisord.conf), e correggi questa riga direttamente.

echo "[include]" | tee -a /opt/python/etc/supervisord.conf 
echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf 
echo "files: celerybeat.conf" | tee -a /opt/python/etc/supervisord.conf 

dovrebbe essere

echo "[include]" | tee -a /opt/python/etc/supervisord.conf 
echo "files: celery.conf celerybeat.conf" | tee -a /opt/python/etc/supervisord.conf 

EDIT:

Per eseguire celerybeat, e assicurarsi che funziona solo una volta su tutte le macchine, è necessario posizionare queste righe nei file di configurazione -

04_killotherbeats: 
    command: "ps auxww | grep 'celery beat' | awk '{print $2}' | sudo xargs kill -9 || true" 
05_restartbeat: 
    command: "supervisorctl -c /opt/python/etc/supervisord.conf restart celerybeat" 
    leader_only: true 
+2

Ho anche dovuto (1) aggiungere '--pidfile =/tmp/celerybeat.pid' al comando Celerybeat in' celerybeat.conf' e (2) aggiungere 'ignoreErrors: true' a' 04_killotherbeats' per farlo funzionare correttamente su un'istanza di lavoratore di elisabianco. –

+0

@HakanB. Puoi spiegarci come il mio demone celibe è stato ucciso a caso e si rifiuta di iniziare a citare il supervisore non trovato? – gauravdott

+0

Tutto funziona bene ma il sedano è pronto per ogni occasione. Il risultato è la duplicazione delle attività periodiche ... –