zodern / meteor-up

Production Quality Meteor Deployment to Anywhere
http://meteor-up.com/
MIT License
1.27k stars 280 forks source link

[Question] Graceful shutdown #589

Open WayneUong opened 7 years ago

WayneUong commented 7 years ago

Is there an option for graceful shutdown during deployment?

zodern commented 7 years ago

@WayneUong could you please give more details? Do you want to shutdown the app, or cancel while deploying the app?

WayneUong commented 7 years ago

@zodern When the app is being deployed, I want to wait till all node processes are done before the old app is shut down and replaced with the new app.

SimonSimCity commented 6 years ago

I was wondering about the same and found out the following:

The command mup stop and mup restart both execute the script https://github.com/zodern/meteor-up/blob/master/src/plugins/meteor/assets/meteor-stop.sh which (at the time writing) stop and remove all docker containers by running docker rm -f $APPNAME.

The documentation of docker states that docker rm -f CONTAINER sends the signal SIGKILL to the process running in this container (https://docs.docker.com/v1.11/engine/reference/commandline/rm/).

An article like https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/ explains very detailed how which of the possible versions of shutting down a container work.

My suggestion here is to replace the forcefully removing calls by something like the following:

# Gracefully stopping the meteor application
sudo docker stop -t $TIMEOUT $APPNAME || :

# Continue with forcefully stopping and removing
sudo docker rm -f $APPNAME || :
sudo docker rm -f $APPNAME-frontend || :
sudo docker rm -f $APPNAME-nginx-letsencrypt || :
sudo docker rm -f $APPNAME-nginx-proxy || :

Doing this will give us the possibility to e.g. gracefully shut down the connections to the client systems and make sure the code is finished and doesn't hick up in the middle of a function.

SimonSimCity commented 6 years ago

To have a graceful shutdown here would also be nice to support this plugin: https://www.npmjs.com/package/@meteorjs/ddp-graceful-shutdown

It would also help me gracefully shutting down my HTTP server I have on Meteor (http://dillonbuchanan.com/programming/gracefully-shutting-down-a-nodejs-http-server/) and certainly also be necessary to detecting jobs that are stopped (https://github.com/vsivsi/meteor-job-collection/pull/263/commits/97822bfbb67f3c3e1a055d34c15770d8f4a76355#diff-04c6e90faac2675aa89e2176d2eec7d8R2034).

SimonSimCity commented 6 years ago

See pull request #964