Health Checks and Graceful Shutdown健康检查和优雅关机

Graceful shutdown平滑关闭

When you deploy a new version of your application, you must replace the previous version. The process manager you’re using will first send a SIGTERM signal to the application to notify it that it will be killed. 部署应用程序的新版本时,必须替换以前的版本。您正在使用的进程管理器将首先向应用程序发送SIGTERM信号,通知它将被终止。Once the application gets this signal, it should stop accepting new requests, finish all the ongoing requests, clean up the resources it used, including database connections and file locks then exit.一旦应用程序收到此信号,它应该停止接受新请求,完成所有正在进行的请求,清理它使用的资源,包括数据库连接和文件锁,然后退出。

Example示例

const server = app.listen(port)

process.on('SIGTERM', () => {
  debug('SIGTERM signal received: closing HTTP server')
  server.close(() => {
    debug('HTTP server closed')
  })
})

Health checks健康检查

A load balancer uses health checks to determine if an application instance is healthy and can accept requests. 负载平衡器使用健康检查来确定应用程序实例是否健康并且可以接受请求。For example, Kubernetes has two health checks:例如,Kubernetes有两个健康检查