【发布时间】:2013-05-06 01:03:39
【问题描述】:
我终于完成了将我的一个项目转换为使用 Node.JS,但现在我在保持我的应用程序在服务器上运行时遇到了问题:/ 问题是,如果我关闭我的 putty 会话,Node 就会停止。
我在这个问题上做了很多搜索,似乎创建一个upstart 脚本并使用Forever 模块是要走的路。
我开始在谷歌上搜索并创建了这个新贵脚本:
#!upstart
description "Loner NodeJS app launcher"
author "me@me.com"
start on startup
stop on shutdown
script
export HOME="/root"
exec sudo node /home/jjmpsp/server.js >> /home/jjmpsp/server.sys.log 2>&1
end script
然后我昨晚在服务器上运行了start app,当我关闭腻子会话时,服务器仍然运行。都很好。
但是,我今天早上来了,发现 Node 应用程序已经停止,所以我检查了 server.sys.log 文件以查看发生了什么。似乎该应用程序运行良好,直到最终遇到此异常:
debug: client authorized
info: handshake authorized fziLHZA3Vo9i55eubvOq
events.js:48
throw arguments[1]; // Unhandled 'error' event
^
Error: Connection lost: The server closed the connection.
at Protocol.end (/home/jjmpsp/node_modules/mysql/lib/protocol/Protocol.js:73:13)
at Socket.onend (stream.js:80:10)
at Socket.emit (events.js:88:20)
at TCP.onread (net.js:348:51)
今天我在谷歌上搜索得更多,发现如果 NodeJS 应用程序意外退出,Forever 实际上会重新启动它。我尝试使用npm install forever 安装模块,但我得到了这个巨大的错误列表:
jjmpsp@alex:~$ npm install forever
npm ERR! error installing forever@0.9.2 Error: No compatible version found: node-fork@'>=0.4.0- <0.5.0-'
npm ERR! error installing forever@0.9.2 No valid targets found.
npm ERR! error installing forever@0.9.2 Perhaps not compatible with your version of node?
npm ERR! error installing forever@0.9.2 at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:424:10)
npm ERR! error installing forever@0.9.2 at /usr/local/lib/node_modules/npm/lib/cache.js:406:17
npm ERR! error installing forever@0.9.2 at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:136:7)
npm ERR! error installing forever@0.9.2 at Object.cb [as oncomplete] (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:36:9)
npm ERR! Error: No compatible version found: node-fork@'>=0.4.0- <0.5.0-'
npm ERR! No valid targets found.
npm ERR! Perhaps not compatible with your version of node?
npm ERR! at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:424:10)
npm ERR! at /usr/local/lib/node_modules/npm/lib/cache.js:406:17
npm ERR! at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:136:7)
npm ERR! at Object.cb [as oncomplete] (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:36:9)
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR!
npm ERR! System Linux 3.8.4-x86_64-linode31
npm ERR! command "node" "/usr/local/bin/npm" "install" "forever"
npm ERR! cwd /home/jjmpsp
npm ERR! node -v v0.5.11-pre
npm ERR! npm -v 1.0.106
npm ERR! Error: EACCESS, Permission denied 'npm-debug.log'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-@googlegroups.com>
npm ERR!
npm ERR! System Linux 3.8.4-x86_64-linode31
npm ERR! command "node" "/usr/local/bin/npm" "install" "forever"
npm ERR! cwd /home/jjmpsp
npm ERR! node -v v0.5.11-pre
npm ERR! npm -v 1.0.106
npm ERR! path npm-debug.log
npm ERR! code EACCESS
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/jjmpsp/npm-debug.log
npm not ok
我应该采取什么步骤来解决这个问题?我完全没有想法。我一直在谷歌上搜索各种技术细节,但我一无所获。
非常感谢任何帮助:)
【问题讨论】:
-
您运行的是旧版本的节点似乎很简单。您可以尝试升级,看看是否有任何不同。要查看您运行的版本,您可以运行 process.version;在节点控制台中。我相信您还想使用全局标志运行安装。 npm install -g 永远
-
jjmpsp@alex:~$ node > process.version 'v0.10.5'
-
我也尝试过运行“sudo npm install -g forever”:/ hmm
-
奇怪的是错误日志还是显示'npm ERR! node -v v0.5.11-pre' 当我知道我正在运行 v0.10.5
标签: node.js ubuntu upstart forever