已经有一个关于这个主题的线程(here),但它没有回答我的情况(大多数答案都提出了替代节点窗口的建议,而不是解决它创建的服务停止运行的原因)。
正如标题所说,我使用 node-windows 包来创建服务(运行我的节点应用程序脚本)。它在本地运行,但是当我将它安装在 Windows 2012 服务器上时,该服务在启动后几秒钟后停止。
以下是在事件查看器中发现的错误:
- 开始 D:\Program Files\nodejs\node.exe --harmony "D:\Program Files\otherApps\create-windows-service-for-nodejs\node_modules\node-windows\lib\wrapper.js" --file " D:\Program Files\path\to\my\application\index.js" --log "Node.js 服务管理 API 包装器" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst undefined
- 服务启动成功。
- 开始 D:\Program Files\path\to\my\application\index.js
- D:\Program Files\path\to\my\application\index.js 停止运行。
- 意外退出后重新启动 1250 毫秒;尝试 = 1
- D:\Program Files\path\to\my\application\index.js 停止运行。
- 意外退出后重新启动 1562.5 毫秒;尝试 = 2
- 子进程 [5800 - D:\Program Files\nodejs\node.exe --harmony "D:\Program Files\otherApps\create-windows-service-for-nodejs\node_modules\node-windows\lib\wrapper.js" --file "D:\Program Files\path\to\my\application\index.js" --log "Node.js 服务管理 API 包装器" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror
这是我对节点窗口的实现:
var Service = require('node-windows').Service;
var svc = new Service({
name:'Node.js Service Management API',
description: 'The nodejs.org service management api.',
script: 'D:\\Program Files\\nodeApps\\service-management-api\\server\\server.js'
});
svc.on('install',function(){
svc.start();
console.log('Install complete');
console.log('The service exists: ', svc.exists)
});
svc.install();
关于如何修复此服务使其保持“开启”的任何建议?这是我对节点窗口的实现吗?或者可能是一些 Windows Server 2012 配置问题?
谢谢!