简体   繁体   English

NodeJS和Forever(监视和重新启动应用程序)

[英]NodeJS and Forever (monitoring and restarting app)

I'm trying to setup forever and NodeJS to monitor&restart my app and also keep it running when exits. 我正在尝试forever设置NodeJS以监视和重新启动我的应用,并在退出时保持其运行。 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? 有什么我缺少的选择吗?

EDIT: 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. 我正在查看〜317行-Monitor.prototype.kill(在monitor.js中),但一切看起来都应该正常工作。

EDIT: 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 在这里检查: https : //github.com/nodejitsu/forever-monitor/issues/27

nodemon and forever are a pain to get running consistently. nodemon和永远永远是持续运行的痛苦。 I would try using a shell script first. 我会先尝试使用Shell脚本。 If you are on linux, just place a monitornode file in /etc/cron.d 如果您使用的是Linux,只需将MonitorNode文件放在/etc/cron.d中

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

and have a script somewhere on your machine 并在您的计算机上的某个地方有一个脚本

Try this if you are getting started, create a file /var/www/nodejs/monitornode.sh and chmod +x : 如果您要开始尝试此操作,请创建一个文件/var/www/nodejs/monitornode.sh和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

nodemonnodemon软件包以完成整个“文件更改时重新加载”的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM