Pm2: [QUESTION] PM2-docker container shutdown best practices

Created on 7 Dec 2017  路  3Comments  路  Source: Unitech/pm2

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:

  • Trap the signal
  • Trigger pm2.disconnect with a configurable kill_timeout that syncs up with our graceful application shutdown timeout.
  • Workers should trap SIGINT from pm2 master and start their graceful shutdown. (server close and tag 503 on in flight requests)

Questions:

  • What's the best way from shell to trigger pm2 disconnect? Should I use the programmatic API or interact with rpc.sock directly?
  • Is 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.

Question

All 3 comments

I setup an example. I think this works fine? Any recommendations would be great. There's some info in the README.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

psparago picture psparago  路  3Comments

ghost picture ghost  路  3Comments

waygee picture waygee  路  4Comments

chaos-git picture chaos-git  路  3Comments

alexpts picture alexpts  路  3Comments