Multiple python commands does not run from bash

91 views Asked by At

I have a bash script that launches wsgi for python and celery as well. The pythib project launes nicely though celery does not work. Below i incluse two ways of invoking the wsgi project and celery and none works as expected.

Way No1

...
echo "the PWD of project now is : ${PWD}"
exec    gunicorn project.wsgi:application \
        --name audit_tool \
        --bind 0.0.0.0:8000 \
        --timeout 1000 \
        --workers 4 \
        --log-level=$level \
        --env DEBUG=${DEBUG} \
        --log-config tmp.conf \
        --preload &&
echo "Gunicorn started"
exec celery -A project worker -Q celery --loglevel=info --concurrency=1 --max-memory-per-child=25000 &&
sleep 2.5
ps aux | grep celery ;
echo 'done'
...
read -r -d '' cmd << end
    gunicorn project.wsgi:application \
        --name audit_tool \
        --bind 0.0.0.0:8000 \
        --timeout 1000 \
        --workers 6 \
        --log-level=$level \
        --env DEBUG=${DEBUG} \
        --log-config tmp.conf \
        --preload
end
echo Starting Gunicorn.
($cmd)
read -r -d '' cmd2 << end
    celery \
        -A project \
            worker \
        -Q celery \
        --loglevel=info \
        --concurrency=1 \
        --max-memory-per-child=25000 
end
echo "Starting celery." 
($cmd2)

Any help would be appreciated !!

I tried the two above ways and expectation was to launch the wsgi project and celery as well.

1

There are 1 answers

5
Mark Setchell On

It depends how you want it to work...

If you want to do thing1, wait till it finishes, then thing2, use:

thing1
thing2

If you want to do thing1 and at the same time thing2, use:

thing1 &
thing2

If thing1 is actually 2 things, thing1A and thing1B, then you can combine them (Do not omit spaces ever. You may omit the semi-colons if the commands are spread across multiple lines):

{ thing1A ; thing1B ; }

So, in answer to your question:

You can do it like this:

{ gunicorn project.wsgi:application \
        --name audit_tool \
        --bind 0.0.0.0:8000 \
        --timeout 1000 \
        --workers 4 \
        --log-level=$level \
        --env DEBUG=${DEBUG} \
        --log-config tmp.conf \
        --preload &&
echo "Gunicorn started" } &

{ celery -A project worker -Q celery --loglevel=info --concurrency=1 --max-memory-per-child=25000 &&
sleep 2.5
ps aux | grep celery } &

So that starts gunicorn and your echo command in the background, and while that is still running, it starts celery, sleep and ps as another group of commands running in parallel with gunicorn.