From 8c48fe082f01ad6f1964e28c609efeea05f72bee Mon Sep 17 00:00:00 2001 From: Charly Koza Date: Wed, 9 Oct 2024 18:32:47 +0200 Subject: [PATCH] feat: allow to disable "end on process signal" handlers Implements #280 --- README.md | 4 ++++ src/index.js | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 33279a3..88eed6d 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,10 @@ A [bunyan logger](https://github.com/trentm/node-bunyan) instance. Created by de Sets the timeout (in ms) after that an idle connection is closed by the server __Default:__ `0` +#### `endOnProcessSignal` +Whether to close ftp server and exit process on SIGTERM/SIGINT/SIGQUIT signals or not +__Default:__ `true` + ## CLI `ftp-srv` also comes with a builtin CLI. diff --git a/src/index.js b/src/index.js index 859540d..fee5955 100644 --- a/src/index.js +++ b/src/index.js @@ -24,7 +24,8 @@ class FtpServer extends EventEmitter { whitelist: [], greeting: null, tls: false, - timeout: 0 + timeout: 0, + endOnProcessSignal: true, }, options); this._greeting = this.setupGreeting(this.options.greeting); @@ -70,9 +71,11 @@ class FtpServer extends EventEmitter { const quit = _.debounce(this.quit.bind(this), 100); - process.on('SIGTERM', quit); - process.on('SIGINT', quit); - process.on('SIGQUIT', quit); + if (this.options.endOnProcessSignal) { + process.on('SIGTERM', quit); + process.on('SIGINT', quit); + process.on('SIGQUIT', quit); + } } get isTLS() {