我终于完成了将我的一个项目转换为使用Node.JS,但现在我遇到了问题,使我的应用程序在服务器上运行:/问题是,如果我关闭我的putty会话节点就会停止。
我在这个问题上做了很多搜索,似乎创建一个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,当我关闭putty会话时,服务器仍然在运行。一切都很好。
然而,今天早上我来了,发现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我应该采取什么步骤来解决这个问题?我完全没有想法了。我一直在谷歌上搜索各种技术细节,但我什么也没得到。
非常感谢您的帮助:)
发布于 2013-11-23 00:57:38
https://unix.stackexchange.com/questions/479/keep-ssh-sessions-running-after-disconnection
执行以下操作:
screen //然后按enter键node server.js
https://stackoverflow.com/questions/16497610
复制相似问题