我終於完成了我的轉化項目中使用Node.js的之一,但現在我有問題,保持我的應用程序在服務器上運行:/的問題是,如果我關閉我的膩子會議節點,只需停止。如何讓節點應用程序運行?
我已經做了大量的搜索這個問題,似乎創建一個upstart
腳本和使用Forever
模塊是要走的路。
我開始使用Google並創造了這個暴發戶腳本:
#!upstart
description "Loner NodeJS app launcher"
author "[email protected]"
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
昨晚和服務器運行呆當我關閉膩子會議。都好。
不過,我來到這個早上,發現該節點的應用程序已經停止,所以我檢查了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。我嘗試安裝與npm install forever
的模塊,但我得到這個巨大的錯誤列表:
[email protected]:~$ npm install forever
npm ERR! error installing [email protected] Error: No compatible version found: [email protected]'>=0.4.0- <0.5.0-'
npm ERR! error installing [email protected] No valid targets found.
npm ERR! error installing [email protected] Perhaps not compatible with your version of node?
npm ERR! error installing [email protected] at installTargetsError (/usr/local/lib/node_modules/npm/lib/cache.js:424:10)
npm ERR! error installing [email protected] at /usr/local/lib/node_modules/npm/lib/cache.js:406:17
npm ERR! error installing [email protected] at saved (/usr/local/lib/node_modules/npm/lib/utils/npm-registry-client/get.js:136:7)
npm ERR! error installing [email protected] 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: [email protected]'>=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! <[email protected]>
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! <[email protected]>
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
我應該採取什麼措施來解決這一問題?我完全沒有想法。我一直在google搜索各種技術細節,而且我什麼都沒有找到。
任何幫助是極大的讚賞:)
似乎建興您運行的是舊版本的節點。你可以嘗試升級,看看它是否有任何改變。要查看運行的版本,可以運行process.version;在節點控制檯中。 我相信你也想運行帶有全局標誌安裝。 npm install -g永久 – 2013-05-11 13:36:56
jjmpsp @ alex:〜$ node > process.version 'v0.10.5' – 2013-05-11 14:16:08
我試過運行'sudo npm install -g forever':/ hmm – 2013-05-11 14:16:59