NodeJS和Forever(监视和重新启动应用程序) [英] NodeJS and Forever (monitoring and restarting app)

查看:514
本文介绍了NodeJS和Forever(监视和重新启动应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置foreverNodeJS来监视和重新启动我的应用,并在退出时保持其运行.目前我有这个:

I'm trying to setup forever and NodeJS to monitor&restart my app and also keep it running when exits. Currently I have this:

var forever = require("forever-monitor");

var child = new(forever.Monitor)('main.js', {
    'silent': false,
    'pidFile': '../pids/app.pid',
    'sourceDir': '.',
    'watch': true,
    'watchDirectory': '.',
    'watchIgnoreDotFiles': null,
    'watchIgnorePatterns': null,
    'logFile': '../logs/forever.log',
    'outFile': '../logs/forever.out',
    'errFile': '../logs/forever.err'
});

child.start();

可以很好地启动我的应用程序,但是当我在文件中进行更改时,它不会重新启动它.有什么我想不到的选择吗?

Which starts my app just fine but it doesn't restart it when I make changes in the file. Is there some option that I'm missing?

深入研究问题后,我发现实际上已检测到文件更改,只是该过程没有重新启动. 我正在查看〜317行-Monitor.prototype.kill(在monitor.js中),但是一切看起来都应该正常工作.

After digging into the problem I found that the file change is detected actually, it's just that the process isn't restarted. I'm looking at line ~317 - Monitor.prototype.kill (in monitor.js) but everything looks like it should work.

我设法解决了这个问题.这是库代码中的错误.在这里检查: https://github.com/nodejitsu/forever-monitor/issues/27

I managed to fix the issue. It's a bug in the library's code. Check here: https://github.com/nodejitsu/forever-monitor/issues/27

推荐答案

nodemon和永远使连续运行变得很痛苦.我会先尝试使用Shell脚本.如果您使用的是Linux,只需将monitornode文件放在/etc/cron.d

nodemon and forever are a pain to get running consistently. I would try using a shell script first. If you are on linux, just place a monitornode file in /etc/cron.d

*/1 * * * * root  /var/www/nodejs/monitornode.sh

在您的计算机上的某个地方有一个脚本

and have a script somewhere on your machine

如果要开始尝试此操作,请创建文件/var/www/nodejs/monitornode.sh和chmod + x:

Try this if you are getting started, create a file /var/www/nodejs/monitornode.sh and chmod +x :

#!/bin/sh

TT_NODE="node /var/www/nodejs/node.js"

# NODEJS Watcher
if [ -z `pgrep -f -x "$TT_NODE"` ] 
then
    echo "Starting $TT_NODE."
    cmdNODE="$TT_NODE >> /var/www/logs/node.log &"
    eval $cmdNODE
fi

这篇关于NodeJS和Forever(监视和重新启动应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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