Skip to content

Commit 90f2bcb

Browse files
committed
Updated docker compose, handle server stop
1 parent 583bcb7 commit 90f2bcb

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Imports
22
import ip from 'ip'
3+
import mongoose from 'mongoose'
4+
import format from 'date-fns/format'
35

46
// App Imports
57
import { PORT, NODE_ENV } from '../config/env'
@@ -8,19 +10,34 @@ import { PORT, NODE_ENV } from '../config/env'
810
export default function (server) {
911
console.info('SETUP - Starting server..')
1012

13+
// Start Server
1114
server.listen(PORT, (error) => {
1215
if (error) {
1316
console.error('ERROR - Unable to start server.')
1417
} else {
1518
console.info(`INFO - Server started on`)
1619
console.info(` Local http://localhost:${ PORT } [${ NODE_ENV }]`)
17-
console.info(` Network http://${ ip.address() }:${ PORT } [${ NODE_ENV }] \n`)
20+
console.info(` Network http://${ ip.address() }:${ PORT } [${ NODE_ENV }]`)
21+
console.info(` Datetime ${ format(new Date(), 'YYYY-MM-DD hh:mm:ss a') }\n`)
1822
}
1923
})
2024

21-
process.on('SIGTERM', function () {
22-
server.close(function () {
23-
console.log('Finished all requests. Server stopped.')
25+
// Stop Server
26+
for(let signal of ['SIGINT', 'SIGTERM']) {
27+
console.log(signal)
28+
29+
process.on(signal, function () {
30+
console.info('INFO - Shutting down server..')
31+
32+
serverProcess.close(function () {
33+
console.info('INFO - Server has been shut down.')
34+
35+
mongoose.connection.close(false, () => {
36+
console.info('INFO - Database disconnected.')
37+
38+
process.exit(0)
39+
})
40+
})
2441
})
25-
})
42+
}
2643
}

deployment/docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ services:
3131
- ../backend/proxy/nginx.conf:/etc/nginx/conf.d/proxy.conf
3232
restart: always
3333
ports:
34-
- 80:80
35-
- 443:443
34+
- "80:80"
35+
- "443:443"
3636
depends_on:
3737
- database
3838
- api

0 commit comments

Comments
 (0)