问题
I have a Nodejs application that included clustering for being uptime and domain for error handling.
Now for achieving zero downtime deployment, I have an instruction but I need help to convert this instruction to Nodejs code (I need an example for it please).
This is the instruction:
- When master starts, give it a symlink to worker code.
- After deploying new code, update symlink
- Send a signal to master: fork new workers!
- Mater tells old workers to shut down, forks new workers from new code.
- Mater process never stop running
Instruction source -> slide number 39
回答1:
For 100% uptime the road is more or less the same regardless of the language you are using:
Store your session tokens in a database rather than in an in-memory array or something. This will allow users to stay logged-in after you swap versions.
Run your server inside a Docker container
Use a proxy to handle swapping containers when you need to run a new server version.
I wrote easy-deploy to handle exactly that, so that I wouldn't need to worry about setting up the proxy every time.
Deploy version 1
easy-deploy -p 80:80 -v some/path:other/path my-image:1
To deploy a new version just run the command with the updated tag name
easy-deploy -p 80:80 -v some/path:other/path my-image:2
The proxy is taken care of.
my-image:1
will be replaced by my-image:2
without letting any request drop.
来源:https://stackoverflow.com/questions/44353368/zero-downtime-deployment-nodejs-application