<p>I am running NodeJs services on a Google Kubernetes Cluster with Preemptible VM instances.
Before such a VM shuts down a <code>&quot;preemption notice&quot;</code> is sent. (as described in the <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/preemptible-vms#about" rel="nofollow noreferrer">docs</a>)</p>
<blockquote>
<p>Compute Engine sends a preemption notice to the instance in the form of an ACPI G2 Soft Off signal</p>
</blockquote>
<p><a href="https://cloud.google.com/compute/docs/instances/preemptible#preemption-process" rel="nofollow noreferrer">source</a></p>
<hr />
<p>I want to know how to handle this signal from inside my NodeJs service?</p>
<p>Is it enough to do it like this?</p>
<pre class="lang-js prettyprint-override"><code>process.on('SIGTERM', () =&gt; { 
  // do stuff to prepare service for shutdown
});
</code></pre>

<p>I'm afraid it's not enough, to make it works you need to add a <a href="https://cloud.google.com/compute/docs/instances/create-start-preemptible-instance#handle_preemption" rel="nofollow noreferrer">shutdown script</a> to your container.</p>
<p>In alternative you can install <code>acpid</code> in your container and listen its events through <a href="https://github.com/chesles/node-acpi" rel="nofollow noreferrer">node-acpi</a>.</p>
<p>Hope this helps.</p>
