我的服务器上有一个node.js脚本,即使在我注销SSH之后也要连续运行。我决定永远使用它。
问题:当我尝试使用forever start app.js
启动node.js脚本时,出现以下错误。是否需要更多配置?
The "sys" module is now called "util". It should have a similar interface.
info: Forever processing file: app.js
{
"process": {
"pid": 24257,
"uid": 0,
"gid": 0,
"cwd": "/home/node/nodejs",
"execPath": "/usr/local/bin/node",
"version": "v0.6.2",
"argv": [
"node",
"/usr/local/bin/forever",
"start",
"app.js"
],
"memoryUsage": {
"rss": 13729792,
"heapTotal": 8367232,
"heapUsed": 5130572
}
},
"os": {
"loadavg": [
0.02734375,
0.0322265625,
0.0009765625
],
"uptime": 1474229.393550878
},
"trace": [
{
"column": 21,
"file": "/usr/local/lib/node_modules/forever/lib/forever/cli.js",
"function": "getOptions",
"line": 172,
"method": null,
"native": false
},
{
"column": 17,
"file": "/usr/local/lib/node_modules/forever/lib/forever/cli.js",
"function": "",
"line": 210,
"method": null,
"native": false
},
{
"column": 19,
"file": "/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
"function": "apply",
"line": 355,
"method": null,
"native": false
},
{
"column": 9,
"file": "/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
"function": "_every",
"line": 28,
"method": null,
"native": false
},
{
"column": 16,
"file": "/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
"function": "apply",
"line": 352,
"method": null,
"native": false
},
{
"column": 9,
"file": "/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
"function": "_every",
"line": 28,
"method": null,
"native": false
},
{
"column": 5,
"file": "Object].invoke (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js",
"function": "[object",
"line": 350,
"method": null,
"native": false
},
{
"column": 8,
"file": "Object].dispatch (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/cli.js",
"function": "[object",
"line": 67,
"method": null,
"native": false
},
{
"column": 21,
"file": "Object].start (/usr/local/lib/node_modules/forever/node_modules/flatiron/lib/flatiron/plugins/cli.js",
"function": "[object",
"line": 52,
"method": null,
"native": false
},
{
"column": 9,
"file": "/usr/local/lib/node_modules/forever/lib/forever/cli.js",
"function": null,
"line": 470,
"method": null,
"native": false
}
],
"stack": [
"TypeError: Cannot call method 'reset' of undefined",
" at getOptions (/usr/local/lib/node_modules/forever/lib/forever/cli.js:172:21)",
" at Object.<anonymous> (/usr/local/lib/node_modules/forever/lib/forever/cli.js:210:17)",
" at apply (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:355:19)",
" at _every (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:28:9)",
" at apply (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:352:16)",
" at _every (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:28:9)",
" at [object Object].invoke (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/router.js:350:5)",
" at [object Object].dispatch (/usr/local/lib/node_modules/forever/node_modules/flatiron/node_modules/director/lib/director/cli.js:67:8)",
" at [object Object].start (/usr/local/lib/node_modules/forever/node_modules/flatiron/lib/flatiron/plugins/cli.js:52:21)",
" at /usr/local/lib/node_modules/forever/lib/forever/cli.js:470:9"
],
"level": "error",
"message": "uncaughtException"
}
其他信息
使用npm install forever -g
永久安装时,我收到以下警告,想知道它是否与问题相关......
npm WARN eventemitter2@0.4.1 package.json: 'contributers' should probably be 'contributors'
npm WARN request@2.1.1 package.json: bugs['web'] should probably be bugs['url']
答案 0 :(得分:6)
我已经解决了这个问题,它是上一版本中的错误,并且它们没有上传到生产中,所以 直接从git安装:
use npm install git://github.com/nodejitsu/forever.git -g
有关详细信息,请参阅问题: https://github.com/nodejitsu/forever/issues/179
答案 1 :(得分:3)
在后端运行流程
$ nohup node simple-server.js > output.log &
Forever的目的是让子进程(例如你的node.js web服务器)连续运行,并在意外退出时自动重启。值得一提的是,还有其他工具可以用更通用的方式为任何程序或编程语言完成此任务:
Monit:http://mmonit.com/monit/
新贵:http://upstart.ubuntu.com/
Daemontools:http://cr.yp.to/daemontools.html
Launchtool:http://people.debian.org/~enrico/launchtool.html
答案 2 :(得分:1)
另请查看http://learnboost.github.com/cluster/作为forever.js的替代方案。它还有许多其他有用的功能。