The service installs but will not start, either straight away or after system reboot, when running the following script from 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";
validation-installer-node-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();
When the Inno Setup installer runs, it definitely installs the service and it is set to "Automatic" in startup type. However, when I restart my machine it does not auto-start.
However, when I run
node validation-installer-node-windows.js
the service installs (after I change the name so it doesn't clash) and autostarts straight away without reboot.
I have also tried running as admin. No special permissions were required when running validation-installer-node-windows.js
from the terminal.
I attempted to trigger .js script using Pascal scripting and AfterInstall
keyword as follows:
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;
Again, the script runs just fine and installs the service. However, like before it does not automatically set the status to "Running" and when hitting the nodejs endpoint it returns an "unable to connect" error which then sees the service status return to blank.
There are a series of log msgs, it starts with:
C:\woolworths-receipt-validation-app1_v2\app.js stopped running.
Then:
Restarted 1250 msecs after unexpected exit; attempts = 1
This iterates to 3 attempts and then the last log shows:
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