1

If I run from the terminal uvicorn main:app --reload everything works.

When putting it in a my_script.sh file with:

#!/bin/bash
exec uvicorn main:app --reload

then nothing happens. Why?

I found this: Uvicorn/FastAPI executable, but it seems unanswered.

1
  • Why do you need the exeec ? Commented Jun 30, 2023 at 12:57

2 Answers 2

1

You can instead add a main method (more specifically, if __name__ == "__main__":) inside your existing Python script (i.e., main.py in your case) or a new Python script, where you run the uvicorn server, allowing you to set parameters, such as host, port, reload, workers, etc. (as shown here), and simply execute that Python script from inside your bash script. Have a look here for all the available options.

import uvicorn

if __name__ == "__main__":
    uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)

Edit: Since you mentioned below that you "have the script defined in the entrypoint section of docker-compose", make sure you give the exact path to the bash script, as well as it has permissions to execute. Have a look at the questions here and here. I would also suggest to take a look at the relevant FastAPI documentation.

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

1 Comment

Hi there, i tried this as well with no result :( I have the script defined in the entrypoint section of docker-compose. When i start it it just exits with errcode 0.
0

you can remove the exes from bash script. might be it is a cause of your failure.

Comments

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.