问题描述
我看过无数关于如何使用 NSSM (http://nssm.cc/) 来启动一个Node.js 进程.
I have seen countless articles on how to use NSSM (http://nssm.cc/) to start a NodeJS process.
所以,我有以下简单的 NodeJS 文件:
So, I have the following simple NodeJS file:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('<p>Hello World</p>');
}).listen(8000);
console.log('Server running on http://localhost:8000/');
我正在使用此命令将 NodeJS 文件安装为 Windows 服务:
I am using this command to install the NodeJS file as a windows service:
"C:\Program Files\SimpleNode\nssm.exe" 安装 SimpleNode "C:\Program Files\SimpleNode\node.exe" "C:\Program Files\SimpleNode\simple.js"
服务已安装.当我启动它时,我收到一条错误消息,服务处于暂停状态,我在事件查看器中看到以下错误:
The service is installed. When I start it I get an error message, the services is in the Paused state and I see the following error in Event Viewer:
GetProcessTimes() 失败:句柄无效.
这应该很简单.我尝试使用具有本地管理员权限的域帐户.我尝试了几个不同的端口号.当我从命令行启动该应用程序时,它确实可以正常工作.
This should be pretty simple. I have tried using a domain account that has local admin rights. I have tried a couple of different port numbers. The app does work correctly when I start it from the command line.
更多注意事项:这是在 64 位 Windows 2008 R2 服务器上运行的.我确保我正在为 NSSM 和 Node.js 运行所有 64 位可执行文件.我也试过对两者都使用 32 位可执行文件.
MORE NOTES:This is running on 64-bit Windows 2008 R2 server. I have made sure I am running all 64-bit executables for both NSSM and Node. I have also tried using 32-bit executables for both.
谁能告诉我我错过了什么?其他人可以复制这个问题吗?
Can anyone tell me what I am missing? Can someone else replicate this issue?
推荐答案
发现问题.
问题在于 simple.js 文件的路径中有一个空格(Good Old "Program Files").您必须使用反斜杠对引号进行转义,以便 NSSM 正确解释它.正确的安装命令行是:
The problem is that is that the path to the simple.js file has a space in it (Good Old "Program Files"). You have to escape the quotes with a backslash for NSSM to interpret it correctly. The correct installation command line is:
"C:\Program Files\SimpleNode\nssm.exe" 安装 SimpleNode "C:\Program Files\SimpleNode\node.exe" \"C:\Program Files\SimpleNode\simple.js\"
这篇关于使用 NSSM 作为 Windows 服务启动 NodeJs 进程不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!