Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'restart' endpoint to server for deploy automation #256

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

WardBrian
Copy link
Collaborator

This was discussed during #253.

This lets us ping /restart with a specific secret to trigger the public server to restart. If the token is not set by the user, this endpoint never does anything.

To actually make use of this, we need to manually re-deploy after a merge, picking some secret to put into both the k8 config and this repo's production environment secrets

@WardBrian
Copy link
Collaborator Author

WardBrian commented Dec 18, 2024

To test:

cd backend/
$ docker build -t stan-playground . 
$ docker run -p 8083:8080 -e SWS_RESTART_TOKEN=4321 -it stan-playground 

Then, in another window

$ curl -X POST http://localhost:8083/restart -H "Authorization: Bearer 4321"

(We should not pick 4321 for the actual token)

@magland
Copy link
Collaborator

magland commented Dec 18, 2024

Cool! But did you test restart with uvicorn?

@WardBrian
Copy link
Collaborator Author

But did you test restart with uvicorn?

What do you mean?

At the end of the curl command I posted in my comment above, the docker image exited completely, so as long as the orchestrator restarts it we should get the behavior we want

@magland
Copy link
Collaborator

magland commented Dec 18, 2024

Oh okay, uvicorn is running inside the container. Got it.

@WardBrian
Copy link
Collaborator Author

Yes, inside the image uvicorn spawns several workers. When a worker gets an authenticated restart POST, it gets the parent process id (which will be uvicorn) and sends it an interrupt. If you look at the logs while this happens, uvicorn interprets this exactly like a Ctrl+C in the terminal, and gracefully shuts down after waiting for any active jobs to finish or the timeout elapses.

Once uvicorn exits, the docker container does too

@magland
Copy link
Collaborator

magland commented Dec 19, 2024

Yes, inside the image uvicorn spawns several workers. When a worker gets an authenticated restart POST, it gets the parent process id (which will be uvicorn) and sends it an interrupt. If you look at the logs while this happens, uvicorn interprets this exactly like a Ctrl+C in the terminal, and gracefully shuts down after waiting for any active jobs to finish or the timeout elapses.

Once uvicorn exits, the docker container does too

Perfect. Seems like this is the right solution.

@WardBrian WardBrian merged commit ad6ea03 into main Dec 19, 2024
2 checks passed
@WardBrian WardBrian deleted the restartable-server branch December 19, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants