Skip to content

Commit b0675d0

Browse files
committed
Handle signals in a Docker friendly way
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.
1 parent 90f2da6 commit b0675d0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

index.js

+9
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ const server = app.listen( port, host, () => {
88
const listenAddress = server.address();
99
logger.info( `pelias is now running on ${listenAddress.address}:${listenAddress.port}` );
1010
});
11+
12+
function exitHandler() {
13+
logger.info('Pelias API shutting down');
14+
15+
server.close();
16+
}
17+
18+
process.on('SIGINT', exitHandler);
19+
process.on('SIGTERM', exitHandler);

0 commit comments

Comments
 (0)