如何在特定时间后强制pm2重新启动? [英] How to force pm2 to restart after a specific amount of time?

查看:899
本文介绍了如何在特定时间后强制pm2重新启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PM2来保持我的node.js应用运行.

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

是否有任何方法可以使PM2每1小时重新启动一次我的应用?

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

推荐答案

将以下代码放入 pm2.js 中,并以pm2 start pm2.js

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.

其他资源:

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

这篇关于如何在特定时间后强制pm2重新启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆