使用 Inno Setup 和 node-windows 脚本将节点应用程序安装为服务时出现问题
Issue with installing node application as a service using Inno Setup and node-windows script
当从 Inno Setup 运行使用以下脚本时,服务会安装但不会立即启动或在系统重新启动后启动:
#define ....
#define NODE "node-v12.16.2-x64.msi"
...
[Files]
...
[Run]
Filename: "{sys}\msiexec.exe"; Parameters: "/passive /i ""{app}\{#NODE}""";
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node In"" program=""{pf64}\nodejs\node.exe"" dir=in action=allow enable=yes"; Flags: runhidden;
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node Out"" program=""{pf64}\nodejs\node.exe"" dir=out action=allow enable=yes"; Flags: runhidden;
Filename: "{pf64}\nodejs\node.exe"; Parameters: "{app}\validation-installer-node-windows.js";
验证安装程序节点-windows.js:
var Service = require('node-windows').Service;
// Create a new service object
var svc = new Service({
name:'receipt-validation-app1_7',
description: 'Testing Team Receipt Validation.',
script: 'C:\xxxxx-receipt-validation-app1_v2\app.js'
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();
当 Inno Setup 安装程序 运行s 时,它肯定会安装该服务,并且在启动类型中设置为“自动”。但是,当我重新启动我的机器时,它不会自动启动。
然而,当我运行
node validation-installer-node-windows.js
服务安装(在我更改名称后它不会冲突)并立即自动启动而无需重新启动。
我也试过 运行ning 作为管理员。从终端 运行ning validation-installer-node-windows.js
时不需要特殊权限。
我尝试使用 Pascal 脚本和 AfterInstall
关键字触发 .js 脚本,如下所示:
Source: "C:\...\validation-installer-node-windows.js"; DestDir: "{app}"; \
Flags: ignoreversion; AfterInstall: RunNodeInstall()
[Run]
; Add Firewall Rules
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node In"" program=""{pf64}\nodejs\node.exe"" dir=in action=allow enable=yes"; Flags: runhidden;
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node Out"" program=""{pf64}\nodejs\node.exe"" dir=out action=allow enable=yes"; Flags: runhidden;
[Code]
procedure RunNodeInstall();
var
ErrorCode: Integer;
begin
if not Shellexec('', 'node', ExpandConstant('{app}\validation-installer-node-windows.js'),'',SW_HIDE,ewWaitUntilTerminated,ErrorCode) then
begin
MsgBox('Issue occured with installing application as a service!', mbInformation, MB_OK);
end;
end;
同样,脚本 运行 可以正常安装服务。但是,像以前一样,它不会自动将状态设置为“运行”,并且当到达 nodejs 端点时,它 return 是一个“无法连接”错误,然后会看到服务状态 return空白。
有一系列日志消息,开头为:
C:\woolworths-receipt-validation-app1_v2\app.js stopped running.
然后:
Restarted 1250 msecs after unexpected exit; attempts = 1
这将迭代到 3 次尝试,然后最后一个日志显示:
Child process [5616 - C:\Program Files\nodejs\node.exe --harmony C:\woolworths-receipt-validation-app1_v2\node_modules\node-windows\lib\wrapper.js --file C:\woolworths-receipt-validation-app1_v2\app.js --scriptoptions= --log "receipt-validation-app1_7 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst undefined] finished with 0
我已经修好了。该错误与 Inno Setup 创建临时目录并在该目录中执行的方式有关。基本上我需要设置 WorkingDir
参数,正如你在上面看到的那样我没有正确设置。
感谢 Martin Prikryl and Corey Butler 为我指明了正确的方向。
ShellExec
的原型如下:
function ShellExec(const Verb, Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var
ErrorCode: Integer): Boolean;
找到here
我已将我的代码修改为以下内容:
procedure InstallNodeApp();
var
ErrorCode: Integer;
var
C, P, D: String;
begin
C := 'node';
P := 'validation-installer-node-windows.js';
D := ExpandConstant('{app}');
if not ShellExec('', C, P, D, SW_HIDE, ewWaitUntilTerminated, ErrorCode) then
begin
ErrorCode:= -1;
MsgBox('Issue occured with installing application as a service!',
mbInformation, MB_OK);
end;
end;
可以确认它运行,安装服务,然后正常工作(连接到 localhost:8090 上的应用程序和 returns 网络应用程序),并保持 运行.
当从 Inno Setup 运行使用以下脚本时,服务会安装但不会立即启动或在系统重新启动后启动:
#define ....
#define NODE "node-v12.16.2-x64.msi"
...
[Files]
...
[Run]
Filename: "{sys}\msiexec.exe"; Parameters: "/passive /i ""{app}\{#NODE}""";
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node In"" program=""{pf64}\nodejs\node.exe"" dir=in action=allow enable=yes"; Flags: runhidden;
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node Out"" program=""{pf64}\nodejs\node.exe"" dir=out action=allow enable=yes"; Flags: runhidden;
Filename: "{pf64}\nodejs\node.exe"; Parameters: "{app}\validation-installer-node-windows.js";
验证安装程序节点-windows.js:
var Service = require('node-windows').Service;
// Create a new service object
var svc = new Service({
name:'receipt-validation-app1_7',
description: 'Testing Team Receipt Validation.',
script: 'C:\xxxxx-receipt-validation-app1_v2\app.js'
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();
当 Inno Setup 安装程序 运行s 时,它肯定会安装该服务,并且在启动类型中设置为“自动”。但是,当我重新启动我的机器时,它不会自动启动。
然而,当我运行
node validation-installer-node-windows.js
服务安装(在我更改名称后它不会冲突)并立即自动启动而无需重新启动。
我也试过 运行ning 作为管理员。从终端 运行ning validation-installer-node-windows.js
时不需要特殊权限。
我尝试使用 Pascal 脚本和 AfterInstall
关键字触发 .js 脚本,如下所示:
Source: "C:\...\validation-installer-node-windows.js"; DestDir: "{app}"; \
Flags: ignoreversion; AfterInstall: RunNodeInstall()
[Run]
; Add Firewall Rules
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node In"" program=""{pf64}\nodejs\node.exe"" dir=in action=allow enable=yes"; Flags: runhidden;
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node Out"" program=""{pf64}\nodejs\node.exe"" dir=out action=allow enable=yes"; Flags: runhidden;
[Code]
procedure RunNodeInstall();
var
ErrorCode: Integer;
begin
if not Shellexec('', 'node', ExpandConstant('{app}\validation-installer-node-windows.js'),'',SW_HIDE,ewWaitUntilTerminated,ErrorCode) then
begin
MsgBox('Issue occured with installing application as a service!', mbInformation, MB_OK);
end;
end;
同样,脚本 运行 可以正常安装服务。但是,像以前一样,它不会自动将状态设置为“运行”,并且当到达 nodejs 端点时,它 return 是一个“无法连接”错误,然后会看到服务状态 return空白。
有一系列日志消息,开头为:
C:\woolworths-receipt-validation-app1_v2\app.js stopped running.
然后:
Restarted 1250 msecs after unexpected exit; attempts = 1
这将迭代到 3 次尝试,然后最后一个日志显示:
Child process [5616 - C:\Program Files\nodejs\node.exe --harmony C:\woolworths-receipt-validation-app1_v2\node_modules\node-windows\lib\wrapper.js --file C:\woolworths-receipt-validation-app1_v2\app.js --scriptoptions= --log "receipt-validation-app1_7 wrapper" --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst undefined] finished with 0
我已经修好了。该错误与 Inno Setup 创建临时目录并在该目录中执行的方式有关。基本上我需要设置 WorkingDir
参数,正如你在上面看到的那样我没有正确设置。
感谢 Martin Prikryl and Corey Butler 为我指明了正确的方向。
ShellExec
的原型如下:
function ShellExec(const Verb, Filename, Params, WorkingDir: String; const ShowCmd: Integer; const Wait: TExecWait; var ErrorCode: Integer): Boolean;
找到here
我已将我的代码修改为以下内容:
procedure InstallNodeApp();
var
ErrorCode: Integer;
var
C, P, D: String;
begin
C := 'node';
P := 'validation-installer-node-windows.js';
D := ExpandConstant('{app}');
if not ShellExec('', C, P, D, SW_HIDE, ewWaitUntilTerminated, ErrorCode) then
begin
ErrorCode:= -1;
MsgBox('Issue occured with installing application as a service!',
mbInformation, MB_OK);
end;
end;
可以确认它运行,安装服务,然后正常工作(连接到 localhost:8090 上的应用程序和 returns 网络应用程序),并保持 运行.