Node.js getting SIGINT from pm2










2















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!










share|improve this question
























  • 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















2















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!










share|improve this question
























  • 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













2












2








2








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!










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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? (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

















  • 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
















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












3 Answers
3






active

oldest

votes


















1














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.






share|improve this answer

























  • 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






  • 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


















1














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






share|improve this answer






























    0














    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/






    share|improve this answer


















    • 1





      No, that dosn’t work. Read my comment above.

      – Fede E.
      May 31 '18 at 2:34










    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer

























    • 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






    • 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















    1














    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.






    share|improve this answer

























    • 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






    • 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













    1












    1








    1







    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.






    share|improve this answer















    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 12 '18 at 15:04

























    answered Jun 11 '18 at 12:16









    TorajaToraja

    113




    113












    • 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






    • 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











    • 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













    1














    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






    share|improve this answer



























      1














      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






      share|improve this answer

























        1












        1








        1







        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






        share|improve this answer













        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 10:06









        dkozlovskyidkozlovskyi

        313




        313





















            0














            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/






            share|improve this answer


















            • 1





              No, that dosn’t work. Read my comment above.

              – Fede E.
              May 31 '18 at 2:34















            0














            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/






            share|improve this answer


















            • 1





              No, that dosn’t work. Read my comment above.

              – Fede E.
              May 31 '18 at 2:34













            0












            0








            0







            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/






            share|improve this answer













            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/







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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












            • 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

















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Edmonton

            Crossroads (UK TV series)