Node.js getting SIGINT from pm2
I'm trying to use pm2 to run my node app as a service.
Right now, starting and stopping the app works. However, I want to do a graceful shutdown.
My app already listens for SIGINT, shutdowns the server and then exits the process. However, trying to put pm2 to send the SIGINT, just causes the app to restart, like if pm2 was killing and starting it again.
This is how I create the process:
pm2 start server.js --name ProcessName --silent --kill-timeout 3000
Here's my app's code for listening the SIGINT:
process.on("SIGINT", function ()
//graceful shutdown
server.end().then(() =>
process.exit();
).catch((err) =>
console.error(err);
);
);
Then to shutdown the app using pm2, I'm running:
pm2 sendSignal SIGINT ProcessName
Which, again, restarts the app.
Reading over pm2 docs, I found that pm2 will also send a shutdown
event to the app, so I added:
process.on('message', function(msg)
if (msg == 'shutdown')
server.end().then(() =>
process.exit();
).catch((err) =>
console.error(err);
);
);
Which isn't working either.
Any idea how to solve this?
Thanks!
node.js pm2
|
show 4 more comments
I'm trying to use pm2 to run my node app as a service.
Right now, starting and stopping the app works. However, I want to do a graceful shutdown.
My app already listens for SIGINT, shutdowns the server and then exits the process. However, trying to put pm2 to send the SIGINT, just causes the app to restart, like if pm2 was killing and starting it again.
This is how I create the process:
pm2 start server.js --name ProcessName --silent --kill-timeout 3000
Here's my app's code for listening the SIGINT:
process.on("SIGINT", function ()
//graceful shutdown
server.end().then(() =>
process.exit();
).catch((err) =>
console.error(err);
);
);
Then to shutdown the app using pm2, I'm running:
pm2 sendSignal SIGINT ProcessName
Which, again, restarts the app.
Reading over pm2 docs, I found that pm2 will also send a shutdown
event to the app, so I added:
process.on('message', function(msg)
if (msg == 'shutdown')
server.end().then(() =>
process.exit();
).catch((err) =>
console.error(err);
);
);
Which isn't working either.
Any idea how to solve this?
Thanks!
node.js pm2
Does your code not crash when you start it normally? (Likenode server.js
)
– njha
May 30 '18 at 22:27
No, it works perfectly fine. And it does catch the SIGINT when I press CTRL+C and exists gracefully (logs some output in the log files and everything).
– Fede E.
May 30 '18 at 23:52
Ah, I misunderstood the question. Shutdown the app withpm2 stop
instead. That sends sigint and doesn't restart it.
– njha
May 31 '18 at 2:30
@ReverseCold already tried that. The stop commands sends a SIGINT but the app never gets it, it does stops the app, but not gracefully. Running pm2 monit you see that a SIGINT was sent. I’m thinking something weird happens and maybe the pm2 wrapper process is killed by the SIGINT instead of the app itself. I don’t know... trying to find an explanation.
– Fede E.
May 31 '18 at 2:33
Does starting the app the regular way and sending a sigint work?
– njha
May 31 '18 at 2:37
|
show 4 more comments
I'm trying to use pm2 to run my node app as a service.
Right now, starting and stopping the app works. However, I want to do a graceful shutdown.
My app already listens for SIGINT, shutdowns the server and then exits the process. However, trying to put pm2 to send the SIGINT, just causes the app to restart, like if pm2 was killing and starting it again.
This is how I create the process:
pm2 start server.js --name ProcessName --silent --kill-timeout 3000
Here's my app's code for listening the SIGINT:
process.on("SIGINT", function ()
//graceful shutdown
server.end().then(() =>
process.exit();
).catch((err) =>
console.error(err);
);
);
Then to shutdown the app using pm2, I'm running:
pm2 sendSignal SIGINT ProcessName
Which, again, restarts the app.
Reading over pm2 docs, I found that pm2 will also send a shutdown
event to the app, so I added:
process.on('message', function(msg)
if (msg == 'shutdown')
server.end().then(() =>
process.exit();
).catch((err) =>
console.error(err);
);
);
Which isn't working either.
Any idea how to solve this?
Thanks!
node.js pm2
I'm trying to use pm2 to run my node app as a service.
Right now, starting and stopping the app works. However, I want to do a graceful shutdown.
My app already listens for SIGINT, shutdowns the server and then exits the process. However, trying to put pm2 to send the SIGINT, just causes the app to restart, like if pm2 was killing and starting it again.
This is how I create the process:
pm2 start server.js --name ProcessName --silent --kill-timeout 3000
Here's my app's code for listening the SIGINT:
process.on("SIGINT", function ()
//graceful shutdown
server.end().then(() =>
process.exit();
).catch((err) =>
console.error(err);
);
);
Then to shutdown the app using pm2, I'm running:
pm2 sendSignal SIGINT ProcessName
Which, again, restarts the app.
Reading over pm2 docs, I found that pm2 will also send a shutdown
event to the app, so I added:
process.on('message', function(msg)
if (msg == 'shutdown')
server.end().then(() =>
process.exit();
).catch((err) =>
console.error(err);
);
);
Which isn't working either.
Any idea how to solve this?
Thanks!
node.js pm2
node.js pm2
edited May 30 '18 at 20:50
Fede E.
asked May 30 '18 at 14:28
Fede E.Fede E.
4721615
4721615
Does your code not crash when you start it normally? (Likenode server.js
)
– njha
May 30 '18 at 22:27
No, it works perfectly fine. And it does catch the SIGINT when I press CTRL+C and exists gracefully (logs some output in the log files and everything).
– Fede E.
May 30 '18 at 23:52
Ah, I misunderstood the question. Shutdown the app withpm2 stop
instead. That sends sigint and doesn't restart it.
– njha
May 31 '18 at 2:30
@ReverseCold already tried that. The stop commands sends a SIGINT but the app never gets it, it does stops the app, but not gracefully. Running pm2 monit you see that a SIGINT was sent. I’m thinking something weird happens and maybe the pm2 wrapper process is killed by the SIGINT instead of the app itself. I don’t know... trying to find an explanation.
– Fede E.
May 31 '18 at 2:33
Does starting the app the regular way and sending a sigint work?
– njha
May 31 '18 at 2:37
|
show 4 more comments
Does your code not crash when you start it normally? (Likenode server.js
)
– njha
May 30 '18 at 22:27
No, it works perfectly fine. And it does catch the SIGINT when I press CTRL+C and exists gracefully (logs some output in the log files and everything).
– Fede E.
May 30 '18 at 23:52
Ah, I misunderstood the question. Shutdown the app withpm2 stop
instead. That sends sigint and doesn't restart it.
– njha
May 31 '18 at 2:30
@ReverseCold already tried that. The stop commands sends a SIGINT but the app never gets it, it does stops the app, but not gracefully. Running pm2 monit you see that a SIGINT was sent. I’m thinking something weird happens and maybe the pm2 wrapper process is killed by the SIGINT instead of the app itself. I don’t know... trying to find an explanation.
– Fede E.
May 31 '18 at 2:33
Does starting the app the regular way and sending a sigint work?
– njha
May 31 '18 at 2:37
Does your code not crash when you start it normally? (Like
node server.js
)– njha
May 30 '18 at 22:27
Does your code not crash when you start it normally? (Like
node server.js
)– njha
May 30 '18 at 22:27
No, it works perfectly fine. And it does catch the SIGINT when I press CTRL+C and exists gracefully (logs some output in the log files and everything).
– Fede E.
May 30 '18 at 23:52
No, it works perfectly fine. And it does catch the SIGINT when I press CTRL+C and exists gracefully (logs some output in the log files and everything).
– Fede E.
May 30 '18 at 23:52
Ah, I misunderstood the question. Shutdown the app with
pm2 stop
instead. That sends sigint and doesn't restart it.– njha
May 31 '18 at 2:30
Ah, I misunderstood the question. Shutdown the app with
pm2 stop
instead. That sends sigint and doesn't restart it.– njha
May 31 '18 at 2:30
@ReverseCold already tried that. The stop commands sends a SIGINT but the app never gets it, it does stops the app, but not gracefully. Running pm2 monit you see that a SIGINT was sent. I’m thinking something weird happens and maybe the pm2 wrapper process is killed by the SIGINT instead of the app itself. I don’t know... trying to find an explanation.
– Fede E.
May 31 '18 at 2:33
@ReverseCold already tried that. The stop commands sends a SIGINT but the app never gets it, it does stops the app, but not gracefully. Running pm2 monit you see that a SIGINT was sent. I’m thinking something weird happens and maybe the pm2 wrapper process is killed by the SIGINT instead of the app itself. I don’t know... trying to find an explanation.
– Fede E.
May 31 '18 at 2:33
Does starting the app the regular way and sending a sigint work?
– njha
May 31 '18 at 2:37
Does starting the app the regular way and sending a sigint work?
– njha
May 31 '18 at 2:37
|
show 4 more comments
3 Answers
3
active
oldest
votes
If you haven't solved it yet...
Based on the information you provided, I assume you are running it on Windows.
Your app cannot catch SIGINT
sent by PM2 on Windows.shutdown
message works on windows too, but it is sent only by gracefulReload
command.
(update)
These are not complete solutions, but might be helpful (hopefully...)
sendSignal
command calls process.kill()
eventually, and some of these signals might work (haven't tried).
I also found the below method. This can gracefully shutdown a process without restarting only if autorestart
option is turned off.
And then your clusters will not reload in case of an accident, so it might not be what you want though...
pm2 lets you send a custom message (reference).
Put the code below in a new file:
var pm2 = require('pm2');
var id = process.argv[2];
pm2.connect(() =>
pm2.sendDataToProcessId(
type: 'shutdown',
data:some: 'data',
id: id,
topic: 'some topic'
, (err, res) =>
console.log('message sent');
pm2.disconnect();
if(err) throw err;
)
);
Modify the part that listens the shutdown
message like below:
process.on('message', function(msg) msg.type == 'shutdown')
// code to clean up
);
And run the first file with node
with id of the cluster you want to shutdown as an argument.
The reason for extra msg.type == 'shutdown'
in the condition is that pm2.sendDataToProcessId()
requires the argument to be an object with those keys, and does not accept simple shutdown
string.
ButgracefulReload
will reload the app after catching the shutdown, right?
– Fede E.
Jun 11 '18 at 13:11
Yes, it does. It didn't?
– Toraja
Jun 11 '18 at 14:54
1
That's the thing. I don't want to restart it. I want to gracefully shut it down.
– Fede E.
Jun 11 '18 at 15:15
I updated my answer, though that's not a complete solution though...
– Toraja
Jun 12 '18 at 15:05
1
@Ian nope. I wans't able to find a solution for this.
– Fede E.
Jan 7 at 14:01
|
show 1 more comment
In general pm2 stop
is the right way to stop your application. However if you run appliation inside of the Docker you need to use pm2-runtime
instead of pm2
which is a part of pm2
npm package and passes system SIGINT
to all child processes. See http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs
add a comment |
Catching the sigint and exiting gracefully should work in your first example.
To actually stop the server, use pm2 stop
instead of pm2 sendSignal SIGINT ProcessName
.
See http://pm2.keymetrics.io/docs/usage/signals-clean-restart/
1
No, that dosn’t work. Read my comment above.
– Fede E.
May 31 '18 at 2:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50607260%2fnode-js-getting-sigint-from-pm2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you haven't solved it yet...
Based on the information you provided, I assume you are running it on Windows.
Your app cannot catch SIGINT
sent by PM2 on Windows.shutdown
message works on windows too, but it is sent only by gracefulReload
command.
(update)
These are not complete solutions, but might be helpful (hopefully...)
sendSignal
command calls process.kill()
eventually, and some of these signals might work (haven't tried).
I also found the below method. This can gracefully shutdown a process without restarting only if autorestart
option is turned off.
And then your clusters will not reload in case of an accident, so it might not be what you want though...
pm2 lets you send a custom message (reference).
Put the code below in a new file:
var pm2 = require('pm2');
var id = process.argv[2];
pm2.connect(() =>
pm2.sendDataToProcessId(
type: 'shutdown',
data:some: 'data',
id: id,
topic: 'some topic'
, (err, res) =>
console.log('message sent');
pm2.disconnect();
if(err) throw err;
)
);
Modify the part that listens the shutdown
message like below:
process.on('message', function(msg) msg.type == 'shutdown')
// code to clean up
);
And run the first file with node
with id of the cluster you want to shutdown as an argument.
The reason for extra msg.type == 'shutdown'
in the condition is that pm2.sendDataToProcessId()
requires the argument to be an object with those keys, and does not accept simple shutdown
string.
ButgracefulReload
will reload the app after catching the shutdown, right?
– Fede E.
Jun 11 '18 at 13:11
Yes, it does. It didn't?
– Toraja
Jun 11 '18 at 14:54
1
That's the thing. I don't want to restart it. I want to gracefully shut it down.
– Fede E.
Jun 11 '18 at 15:15
I updated my answer, though that's not a complete solution though...
– Toraja
Jun 12 '18 at 15:05
1
@Ian nope. I wans't able to find a solution for this.
– Fede E.
Jan 7 at 14:01
|
show 1 more comment
If you haven't solved it yet...
Based on the information you provided, I assume you are running it on Windows.
Your app cannot catch SIGINT
sent by PM2 on Windows.shutdown
message works on windows too, but it is sent only by gracefulReload
command.
(update)
These are not complete solutions, but might be helpful (hopefully...)
sendSignal
command calls process.kill()
eventually, and some of these signals might work (haven't tried).
I also found the below method. This can gracefully shutdown a process without restarting only if autorestart
option is turned off.
And then your clusters will not reload in case of an accident, so it might not be what you want though...
pm2 lets you send a custom message (reference).
Put the code below in a new file:
var pm2 = require('pm2');
var id = process.argv[2];
pm2.connect(() =>
pm2.sendDataToProcessId(
type: 'shutdown',
data:some: 'data',
id: id,
topic: 'some topic'
, (err, res) =>
console.log('message sent');
pm2.disconnect();
if(err) throw err;
)
);
Modify the part that listens the shutdown
message like below:
process.on('message', function(msg) msg.type == 'shutdown')
// code to clean up
);
And run the first file with node
with id of the cluster you want to shutdown as an argument.
The reason for extra msg.type == 'shutdown'
in the condition is that pm2.sendDataToProcessId()
requires the argument to be an object with those keys, and does not accept simple shutdown
string.
ButgracefulReload
will reload the app after catching the shutdown, right?
– Fede E.
Jun 11 '18 at 13:11
Yes, it does. It didn't?
– Toraja
Jun 11 '18 at 14:54
1
That's the thing. I don't want to restart it. I want to gracefully shut it down.
– Fede E.
Jun 11 '18 at 15:15
I updated my answer, though that's not a complete solution though...
– Toraja
Jun 12 '18 at 15:05
1
@Ian nope. I wans't able to find a solution for this.
– Fede E.
Jan 7 at 14:01
|
show 1 more comment
If you haven't solved it yet...
Based on the information you provided, I assume you are running it on Windows.
Your app cannot catch SIGINT
sent by PM2 on Windows.shutdown
message works on windows too, but it is sent only by gracefulReload
command.
(update)
These are not complete solutions, but might be helpful (hopefully...)
sendSignal
command calls process.kill()
eventually, and some of these signals might work (haven't tried).
I also found the below method. This can gracefully shutdown a process without restarting only if autorestart
option is turned off.
And then your clusters will not reload in case of an accident, so it might not be what you want though...
pm2 lets you send a custom message (reference).
Put the code below in a new file:
var pm2 = require('pm2');
var id = process.argv[2];
pm2.connect(() =>
pm2.sendDataToProcessId(
type: 'shutdown',
data:some: 'data',
id: id,
topic: 'some topic'
, (err, res) =>
console.log('message sent');
pm2.disconnect();
if(err) throw err;
)
);
Modify the part that listens the shutdown
message like below:
process.on('message', function(msg) msg.type == 'shutdown')
// code to clean up
);
And run the first file with node
with id of the cluster you want to shutdown as an argument.
The reason for extra msg.type == 'shutdown'
in the condition is that pm2.sendDataToProcessId()
requires the argument to be an object with those keys, and does not accept simple shutdown
string.
If you haven't solved it yet...
Based on the information you provided, I assume you are running it on Windows.
Your app cannot catch SIGINT
sent by PM2 on Windows.shutdown
message works on windows too, but it is sent only by gracefulReload
command.
(update)
These are not complete solutions, but might be helpful (hopefully...)
sendSignal
command calls process.kill()
eventually, and some of these signals might work (haven't tried).
I also found the below method. This can gracefully shutdown a process without restarting only if autorestart
option is turned off.
And then your clusters will not reload in case of an accident, so it might not be what you want though...
pm2 lets you send a custom message (reference).
Put the code below in a new file:
var pm2 = require('pm2');
var id = process.argv[2];
pm2.connect(() =>
pm2.sendDataToProcessId(
type: 'shutdown',
data:some: 'data',
id: id,
topic: 'some topic'
, (err, res) =>
console.log('message sent');
pm2.disconnect();
if(err) throw err;
)
);
Modify the part that listens the shutdown
message like below:
process.on('message', function(msg) msg.type == 'shutdown')
// code to clean up
);
And run the first file with node
with id of the cluster you want to shutdown as an argument.
The reason for extra msg.type == 'shutdown'
in the condition is that pm2.sendDataToProcessId()
requires the argument to be an object with those keys, and does not accept simple shutdown
string.
edited Jun 12 '18 at 15:04
answered Jun 11 '18 at 12:16
TorajaToraja
113
113
ButgracefulReload
will reload the app after catching the shutdown, right?
– Fede E.
Jun 11 '18 at 13:11
Yes, it does. It didn't?
– Toraja
Jun 11 '18 at 14:54
1
That's the thing. I don't want to restart it. I want to gracefully shut it down.
– Fede E.
Jun 11 '18 at 15:15
I updated my answer, though that's not a complete solution though...
– Toraja
Jun 12 '18 at 15:05
1
@Ian nope. I wans't able to find a solution for this.
– Fede E.
Jan 7 at 14:01
|
show 1 more comment
ButgracefulReload
will reload the app after catching the shutdown, right?
– Fede E.
Jun 11 '18 at 13:11
Yes, it does. It didn't?
– Toraja
Jun 11 '18 at 14:54
1
That's the thing. I don't want to restart it. I want to gracefully shut it down.
– Fede E.
Jun 11 '18 at 15:15
I updated my answer, though that's not a complete solution though...
– Toraja
Jun 12 '18 at 15:05
1
@Ian nope. I wans't able to find a solution for this.
– Fede E.
Jan 7 at 14:01
But
gracefulReload
will reload the app after catching the shutdown, right?– Fede E.
Jun 11 '18 at 13:11
But
gracefulReload
will reload the app after catching the shutdown, right?– Fede E.
Jun 11 '18 at 13:11
Yes, it does. It didn't?
– Toraja
Jun 11 '18 at 14:54
Yes, it does. It didn't?
– Toraja
Jun 11 '18 at 14:54
1
1
That's the thing. I don't want to restart it. I want to gracefully shut it down.
– Fede E.
Jun 11 '18 at 15:15
That's the thing. I don't want to restart it. I want to gracefully shut it down.
– Fede E.
Jun 11 '18 at 15:15
I updated my answer, though that's not a complete solution though...
– Toraja
Jun 12 '18 at 15:05
I updated my answer, though that's not a complete solution though...
– Toraja
Jun 12 '18 at 15:05
1
1
@Ian nope. I wans't able to find a solution for this.
– Fede E.
Jan 7 at 14:01
@Ian nope. I wans't able to find a solution for this.
– Fede E.
Jan 7 at 14:01
|
show 1 more comment
In general pm2 stop
is the right way to stop your application. However if you run appliation inside of the Docker you need to use pm2-runtime
instead of pm2
which is a part of pm2
npm package and passes system SIGINT
to all child processes. See http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs
add a comment |
In general pm2 stop
is the right way to stop your application. However if you run appliation inside of the Docker you need to use pm2-runtime
instead of pm2
which is a part of pm2
npm package and passes system SIGINT
to all child processes. See http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs
add a comment |
In general pm2 stop
is the right way to stop your application. However if you run appliation inside of the Docker you need to use pm2-runtime
instead of pm2
which is a part of pm2
npm package and passes system SIGINT
to all child processes. See http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs
In general pm2 stop
is the right way to stop your application. However if you run appliation inside of the Docker you need to use pm2-runtime
instead of pm2
which is a part of pm2
npm package and passes system SIGINT
to all child processes. See http://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs
answered Nov 13 '18 at 10:06
dkozlovskyidkozlovskyi
313
313
add a comment |
add a comment |
Catching the sigint and exiting gracefully should work in your first example.
To actually stop the server, use pm2 stop
instead of pm2 sendSignal SIGINT ProcessName
.
See http://pm2.keymetrics.io/docs/usage/signals-clean-restart/
1
No, that dosn’t work. Read my comment above.
– Fede E.
May 31 '18 at 2:34
add a comment |
Catching the sigint and exiting gracefully should work in your first example.
To actually stop the server, use pm2 stop
instead of pm2 sendSignal SIGINT ProcessName
.
See http://pm2.keymetrics.io/docs/usage/signals-clean-restart/
1
No, that dosn’t work. Read my comment above.
– Fede E.
May 31 '18 at 2:34
add a comment |
Catching the sigint and exiting gracefully should work in your first example.
To actually stop the server, use pm2 stop
instead of pm2 sendSignal SIGINT ProcessName
.
See http://pm2.keymetrics.io/docs/usage/signals-clean-restart/
Catching the sigint and exiting gracefully should work in your first example.
To actually stop the server, use pm2 stop
instead of pm2 sendSignal SIGINT ProcessName
.
See http://pm2.keymetrics.io/docs/usage/signals-clean-restart/
answered May 31 '18 at 2:33
njhanjha
5701416
5701416
1
No, that dosn’t work. Read my comment above.
– Fede E.
May 31 '18 at 2:34
add a comment |
1
No, that dosn’t work. Read my comment above.
– Fede E.
May 31 '18 at 2:34
1
1
No, that dosn’t work. Read my comment above.
– Fede E.
May 31 '18 at 2:34
No, that dosn’t work. Read my comment above.
– Fede E.
May 31 '18 at 2:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50607260%2fnode-js-getting-sigint-from-pm2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Does your code not crash when you start it normally? (Like
node server.js
)– njha
May 30 '18 at 22:27
No, it works perfectly fine. And it does catch the SIGINT when I press CTRL+C and exists gracefully (logs some output in the log files and everything).
– Fede E.
May 30 '18 at 23:52
Ah, I misunderstood the question. Shutdown the app with
pm2 stop
instead. That sends sigint and doesn't restart it.– njha
May 31 '18 at 2:30
@ReverseCold already tried that. The stop commands sends a SIGINT but the app never gets it, it does stops the app, but not gracefully. Running pm2 monit you see that a SIGINT was sent. I’m thinking something weird happens and maybe the pm2 wrapper process is killed by the SIGINT instead of the app itself. I don’t know... trying to find an explanation.
– Fede E.
May 31 '18 at 2:33
Does starting the app the regular way and sending a sigint work?
– njha
May 31 '18 at 2:37