How to force pm2 to restart after a specific amount of time?

你说的曾经没有我的故事 提交于 2019-12-05 08:08:53

问题


I am using PM2 to keep my node.js apps running.

Is there any way to have PM2 restart my app every 1 hour?


回答1:


Put the code below in pm2.js and start it with pm2 start pm2.js

    var pm2 = require('pm2');

  pm2.connect(function(err) {
    if (err) throw err;

  setTimeout(function worker() {
    console.log("Restarting app...");
    pm2.restart('app', function() {});
    setTimeout(worker, 1000);
    }, 1000);
  });

More about this can be found here.

Additional resources:

  • How can I programmatically shutdown a node program and restart it?
  • Programmatically watch and restart node server


来源:https://stackoverflow.com/questions/38061854/how-to-force-pm2-to-restart-after-a-specific-amount-of-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!