Florian Ludewig
Florian Ludewig

Reputation: 6002

How to catch preemption notice in NodeJs when running on a GKE cluster?

I am running NodeJs services on a Google Kubernetes Cluster with Preemptible VM instances. Before such a VM shuts down a "preemption notice" is sent. (as described in the docs)

Compute Engine sends a preemption notice to the instance in the form of an ACPI G2 Soft Off signal

source


I want to know how to handle this signal from inside my NodeJs service?

Is it enough to do it like this?

process.on('SIGTERM', () => { 
  // do stuff to prepare service for shutdown
});

Upvotes: 4

Views: 422

Answers (1)

Daniele Ricci
Daniele Ricci

Reputation: 15797

I'm afraid it's not enough, to make it works you need to add a shutdown script to your container.

In alternative you can install acpid in your container and listen its events through node-acpi.

Hope this helps.

Upvotes: 1

Related Questions