我终于完成了将我的一个项目转换为使用 Node.JS,但现在我在保持我的应用程序在服务器上运行时遇到了问题:/ 问题是,如果我关闭我的腻子会话,节点就会停止。
我在这个问题上做了很多搜索,似乎创建一个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
我应该采取什么步骤来解决这个问题?我完全没有想法。我一直在谷歌上搜索各种技术细节,但我一无所获。
任何帮助是极大的赞赏 :)