I'm currently interested in container shutdown best practices. Right now, our PaaS/CaaS has agents running that would send a SIGTERM followed by SIGKILL. The container init script will trap signals and act accordingly.
For SIGTERM my thoughts are:
pm2.disconnect with a configurable kill_timeout that syncs up with our graceful application shutdown timeout.SIGINT from pm2 master and start their graceful shutdown. (server close and tag 503 on in flight requests)Questions:
rpc.sock directly?pm2.disconnect() the right approach here? Meaning.. will disconnect go through gracefulShutdown of each worker and allow it to exit?Maybe this is handled if pm2-docker were PID 1, but we need some extra work in init scripts. So we poll pm2 process and exit init script of PID 1 to exit container and this is what platform responds to.
This is indeed handled by pm2-docker (see this), for your questions :
The PM2 disconnect should only be used with the API in JS land, because when you use the API, the client need to connect to it and then the disconnect will cleanup the connection. So i don't see why you'd want to do that in your example.
What you can do is simply a pm2 stop all, it will send the signal to each workers.
Thanks @vmarchaud
That is definitely what I want. Doing that in this setup.