I have a node.js script on my server that I want to run continuously even after I logout of SSH. I decided to use forever for this.
我的服务器上有一个node.js脚本,即使在我注销SSH之后我也要连续运行。我决定永远用这个。
Problem: When I try to start the node.js script using forever start app.js
, I get the following error. Is there more configuration that is required?
问题:当我尝试使用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"
}
Additional Info
When installing forever using npm install forever -g
, I get the following warnings, wonder if its relevant to the problem...
当使用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']
3 个解决方案
#1
3
To run process at the back end
在后端运行进程
$ nohup node simple-server.js > output.log &
The purpose of Forever is to keep a child process (such as your node.js web server) running continuously and automatically restart it when it exits unexpectedly. It's worth mentioning that there are other tools written to accomplish this task in a more generic way for any program or programming language:
Forever的目的是让子进程(例如你的node.js web服务器)连续运行,并在意外退出时自动重启它。值得一提的是,还有其他工具可以用更通用的方式为任何程序或编程语言完成此任务:
Monit: http://mmonit.com/monit/
Upstart: http://upstart.ubuntu.com/
Daemontools: http://cr.yp.to/daemontools.html
Launchtool: http://people.debian.org/~enrico/launchtool.html
Monit:http://mmonit.com/monit/ Upstart:http://upstart.ubuntu.com/ Daemontools:http://cr.yp.to/daemontools.html Launchtool:http://people.debian.org /~enrico/launchtool.html
#2
6
I've solved the problem, it was bug in last release and they didn't upload to production, so install directly from git:
我已经解决了这个问题,它是上一版本中的bug而且他们没有上传到生产中,所以直接从git安装:
use npm install git://github.com/nodejitsu/forever.git -g
使用npm install git://github.com/nodejitsu/forever.git -g
for details see the issue: https://github.com/nodejitsu/forever/issues/179
有关详细信息,请参阅问题:https://github.com/nodejitsu/forever/issues/179
#3
1
Also check out http://learnboost.github.com/cluster/ as alternative to forever.js. It has many other helpful features.
另请查看http://learnboost.github.com/cluster/作为forever.js的替代方案。它还有许多其他有用的功能。
You can also use unix command 'screen' or 'byobu' to keep the ssh sessions from dying.
您还可以使用unix命令'screen'或'byobu'来防止ssh会话死亡。
#1
3
To run process at the back end
在后端运行进程
$ nohup node simple-server.js > output.log &
The purpose of Forever is to keep a child process (such as your node.js web server) running continuously and automatically restart it when it exits unexpectedly. It's worth mentioning that there are other tools written to accomplish this task in a more generic way for any program or programming language:
Forever的目的是让子进程(例如你的node.js web服务器)连续运行,并在意外退出时自动重启它。值得一提的是,还有其他工具可以用更通用的方式为任何程序或编程语言完成此任务:
Monit: http://mmonit.com/monit/
Upstart: http://upstart.ubuntu.com/
Daemontools: http://cr.yp.to/daemontools.html
Launchtool: http://people.debian.org/~enrico/launchtool.html
Monit:http://mmonit.com/monit/ Upstart:http://upstart.ubuntu.com/ Daemontools:http://cr.yp.to/daemontools.html Launchtool:http://people.debian.org /~enrico/launchtool.html
#2
6
I've solved the problem, it was bug in last release and they didn't upload to production, so install directly from git:
我已经解决了这个问题,它是上一版本中的bug而且他们没有上传到生产中,所以直接从git安装:
use npm install git://github.com/nodejitsu/forever.git -g
使用npm install git://github.com/nodejitsu/forever.git -g
for details see the issue: https://github.com/nodejitsu/forever/issues/179
有关详细信息,请参阅问题:https://github.com/nodejitsu/forever/issues/179
#3
1
Also check out http://learnboost.github.com/cluster/ as alternative to forever.js. It has many other helpful features.
另请查看http://learnboost.github.com/cluster/作为forever.js的替代方案。它还有许多其他有用的功能。
You can also use unix command 'screen' or 'byobu' to keep the ssh sessions from dying.
您还可以使用unix命令'screen'或'byobu'来防止ssh会话死亡。