健康检查和正常关机

¥Health Checks and Graceful Shutdown

正常关机

¥Graceful shutdown

当你部署新版本的应用时,你必须替换以前的版本。你使用的进程管理器将首先向应用发送 SIGTERM 信号,通知它将被终止。一旦应用收到此信号,它应该停止接受新请求,完成所有正在进行的请求,清理它使用的资源,包括数据库连接和文件锁,然后退出。

¥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. 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

负载均衡器使用健康检查来确定应用实例是否健康并且可以接受请求。例如,Kubernetes 有两个健康检查

¥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: