Skip to content

Instantly share code, notes, and snippets.

@ezequieltejada
Last active October 7, 2022 10:41
Show Gist options
  • Save ezequieltejada/150a3e1690b9517ec4c0dc6a1235595e to your computer and use it in GitHub Desktop.
Save ezequieltejada/150a3e1690b9517ec4c0dc6a1235595e to your computer and use it in GitHub Desktop.
App Engine gracefully handle shutdown

How to handle shutdown gracefully in an App Engine.

app.get('/_ah/stop', (req, res) => {
  console.info('Shutting down.');
  server.close();
  res.send();
});

app.get('/_ah/start', (req, res) => {
  res.send();
});

app.get('/health-check', (req, res) => {
  res.send();
});

process.on('SIGTERM', () => {
  console.info('SIGTERM signal received: closing HTTP server');
  server.close(() => {
    console.info('HTTP server closed');
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment