Skip to content

Commit

Permalink
fix(ignitor signalslistener): always listen for SIGINT, add server sh…
Browse files Browse the repository at this point in the history
…utting down message

This commit will make Ignitor to always listen for SIGINT so server is killable in containers.

adonisjs-community/create-adonis-ts-app#5
  • Loading branch information
McSneaky committed Mar 7, 2020
1 parent 42b89ae commit 3322713
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Ignitor/SignalsListener/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Exposes the API to invoke a callback when `SIGTERM` or
* `SIGINT (pm2 only)` signals are received.
* `SIGINT` signals are received.
*/
export class SignalsListener {
protected onCloseCallback?: () => Promise<void>
Expand All @@ -19,6 +19,7 @@ export class SignalsListener {
*/
private kill = async function () {
try {
console.log('Shutting down server...')
await this.onCloseCallback()
process.exit(0)
} catch (error) {
Expand All @@ -32,10 +33,8 @@ export class SignalsListener {
*/
public listen (callback: () => Promise<void>) {
this.onCloseCallback = callback
if (process.env.pm_id) {
process.on('SIGINT', this.kill)
}

process.on('SIGINT', this.kill)
process.on('SIGTERM', this.kill)
}

Expand Down

0 comments on commit 3322713

Please sign in to comment.