Skip to content

Commit c8e34a7

Browse files
committed
Add explicit SIGTERM listener for docker shutdown handling, fix link in readme
1 parent affc50a commit c8e34a7

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ The output is placed in `build`.
3636

3737
### With Docker
3838

39-
You can deploy using the [Docker Hub image](https://hub.docker.com/repository/docker/refacto/refacto/general):
39+
You can deploy using the [Docker Hub image](https://hub.docker.com/r/refacto/refacto):
4040

4141
```sh
42-
docker run -d -e INSECURE_SHARED_ACCOUNT_ENABLED=true refacto/refacto
42+
docker run -d -e INSECURE_SHARED_ACCOUNT_ENABLED=true -p 5000:5000 refacto/refacto
4343
```
4444

4545
(see the image details for information on how to configure and secure docker deployments).

backend/src/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,22 @@ function getConnectionCount(s: Server): Promise<number> {
7373
}
7474

7575
let interrupted = false;
76-
process.on('SIGINT', async () => {
77-
// SIGINT is sent twice in quick succession, so ignore the second
78-
if (!interrupted) {
79-
interrupted = true;
80-
printInfo('');
81-
try {
82-
await Promise.all(shutdownTasks.map((fn) => fn()));
83-
await logService.close();
84-
printInfo('Shutdown complete');
85-
} catch (e) {
86-
printError('Failed to shutdown server', e);
87-
}
76+
const shutdown = async () => {
77+
if (interrupted) {
78+
return;
8879
}
89-
});
80+
interrupted = true;
81+
printInfo('');
82+
try {
83+
await Promise.all(shutdownTasks.map((fn) => fn()));
84+
await logService.close();
85+
printInfo('Shutdown complete');
86+
} catch (e) {
87+
printError('Failed to shutdown server', e);
88+
}
89+
};
90+
process.on('SIGINT', shutdown); // respond to Ctrl+C from terminal
91+
process.on('SIGTERM', shutdown); // e.g. sent by Docker when container is stopped
9092

9193
(async () => {
9294
let success = true;

0 commit comments

Comments
 (0)