End execution signal


#1

Hi folks,

any way to catch a end execution signal? I want to save my ‘persisten’ data before system shutdown.

Cheers!
Fer.


#2

Hi @gunderwulde,

you can listen on SIGTERM, then you have 5 seconds to do all the clean up before the system forces a shutdown:

process.on("SIGTERM", function () {
  console.log("SIGTERM received, cleaning up...");
  process.exit(0);
});

remember to call process.exit at the end of the SIGTERM handler. If you use async functions to persist the data, remember that you also need to call process.exit(0) asynchronously :slight_smile: .


Init.sh / Container Lifecycle Questions
#3

Damn, i forgot the process.exit!!!

Thanks etamponi,