Skip to content

Commit

Permalink
Handle signals in a Docker friendly way
Browse files Browse the repository at this point in the history
Similar to pelias/placeholder#160, this small
change allows `ctrl+C` to immediately and gracefully shut down a docker
container started with `docker run pelias/api`.

It's a nice user experience improvement for people running our
containers on the command line.
  • Loading branch information
orangejulius committed Aug 16, 2019
1 parent 90f2da6 commit b0675d0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ const server = app.listen( port, host, () => {
const listenAddress = server.address();
logger.info( `pelias is now running on ${listenAddress.address}:${listenAddress.port}` );
});

function exitHandler() {
logger.info('Pelias API shutting down');

server.close();
}

process.on('SIGINT', exitHandler);
process.on('SIGTERM', exitHandler);

0 comments on commit b0675d0

Please sign in to comment.