0

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.

9
  • Try removing exec everywhere. Commented Feb 25, 2023 at 8:23
  • This might help: How to debug a bash script? Commented Feb 25, 2023 at 8:30
  • @MarkSetchell in the second approach i dont use exec and i have the exact same result Commented Feb 25, 2023 at 11:52
  • I was referring to the first example, which does have exec. When you say it doesn't work, what happens exactly? Commented Feb 25, 2023 at 12:00
  • @MarkSetchell it executes the gunicorn project.wsgi:application and stops there its does not executes the celery part Commented Feb 25, 2023 at 12:23

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

adding those {} made the container failed , removing them it still runs only gunicorn. Very strange behaviour
Are you sure you are using bash. Do you have a proper shebang at the start? You can change the curly brackets for round ones and try.
Positively using bash :-) i will try with parentesis
no luck so far trying all sorts of variations.
Try simplifying it till it works gunicorn PARAMETERS & on one line then celery PARAMETERS & on the next, without all the echo and sleep and ps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.