Using NSSM to start a NodeJs process as a windows service is not working

别等时光非礼了梦想. 提交于 2019-12-05 13:12:39

问题


I have seen countless articles on how to use NSSM (http://nssm.cc/) to start a NodeJS process.

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/');

I am using this command to install the NodeJS file as a windows service:

"C:\Program Files\SimpleNode\nssm.exe" install 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() failed: The handle is invalid.

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.

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?


回答1:


Found the issue.

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" install SimpleNode "C:\Program Files\SimpleNode\node.exe" \"C:\Program Files\SimpleNode\simple.js\"




回答2:


It sounds like you don't have access to ports for some reason. try setting the service to run as administrator (server Manager>Services>Servicename on windows server 2008) and see what happens.




回答3:


NSSM usually works fine with Node.js so this is probably a permissions issue. Review this tutorial showing how to setup Node.js with our commercial application to troubleshoot. And feel free to use the 30-day trial too as it it may return a more helpful error message indicating what the problem is.



来源:https://stackoverflow.com/questions/16427301/using-nssm-to-start-a-nodejs-process-as-a-windows-service-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!