使用inno setup脚本注册启动节点服务器后无法启动windows服务

问题描述 投票:0回答:1

Stack Overflow 社区您好,

我遇到了 Inno Setup 脚本的问题,需要一些帮助。在安装可执行文件(Exe)期间,我必须注册一个 Windows 服务来启动我的节点服务器来运行我的 Angular ssr 构建。但创建 Windows 服务后,它显示

pause
状态,当我手动启动/暂停 Windows 服务时,我收到错误。

启动节点服务器的实际命令,用于运行我的 Angular ssr。

"C:\Program Files\nodejs\node" "C:\Program Files (x86)\envVarIssue\ecom\angular\server\main.js"

当我在 cmd 中运行上述命令时,它运行完美。

但我必须使用 Windows 服务启动服务器。因此,我在安装 exe 应用程序期间安装了 Windows 服务、node.msi。

当我安装exe时,Windows服务创建,但它没有启动。它显示暂停状态。

请参阅下面的错误附件

对于我使用的注册Windows服务,

nssm

任何人都可以帮助我理解为什么会出现此问题以及如何解决它?谢谢您的协助。

我提供了我的代码,请检查。

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "envVarIssue"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "https://www.example.com/"
#define MyAppExeName "MyProg.exe"
#define MyAppAssocName MyAppName + " File"
#define MyAppAssocExt ".myp"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt

#define MyAppParentPath "."

#define MyAppShortName "ecomNodeServer"

#define NODE64 "node-v21.6.2-x64.msi"
#define NSSM64 "nssm.exe"

[Setup]
SetupLogging=yes
ChangesEnvironment=yes

; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{D2C055CB-72E7-4DB9-83EE-34D399939D0C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
PrivilegesRequired=admin
OutputBaseFilename=envVarIssue App
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Program Files (x86)\Inno Setup 6\Examples\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion;
Source: "{#MyAppParentPath}\ecom\angular\*"; DestDir: "{app}\ecom\angular"; Flags: ignoreversion recursesubdirs createallsubdirs;
;Source: "{#MyAppParentPath}\ecom\node-v20.11.1-win-x64\*"; DestDir: "{app}\ecom\node-v20.11.1-win-x64"; Flags: ignoreversion recursesubdirs createallsubdirs;

; uncomment for you want to install node via .msi 
Source: "{#MyAppParentPath}\winstaller\{#NODE64}"; DestDir: "{app}"; Flags: ignoreversion;
Source: "{#MyAppParentPath}\ecom\nssm-2.24\win64\{#NSSM64}"; DestDir: "{app}"; Flags: ignoreversion

; NOTE: Don't use "Flags: ignoreversion" on any shared system files


[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
; Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
; install service without installation node
;Filename: "{app}\{#NSSM64}"; \
    Parameters: "install {#MyAppShortName} ""{app}\ecom\node-v20.11.1-win-x64\node.exe"" ""{app}\ecom\angular\server\main.js"""; \
    Description: "Installing Node Server service"; \
    StatusMsg: "Installing Node Server service..."; \
    Flags: runascurrentuser runhidden;

;Filename: "{cmd}"; \
    Parameters: "/c nssm set {#MyAppShortName} description ""test"" && nssm set {#MyAppShortName} DisplayName ""ECOM NODE SERVER"" && nssm set {#MyAppShortName} start SERVICE_DELAYED_AUTO_START"; \
    WorkingDir: "{app}"; \
    Description: "Configure Node Server service"; \
    StatusMsg: "Configure Node Server service..."; \
    Flags: runascurrentuser runhidden;

;Filename: "{app}\{#NSSM64}"; \
    Parameters: "start {#MyAppShortName}"; \
    Description: "Configure Node Server service"; \
    StatusMsg: "Configure Node Server service..."; \
    Flags: runascurrentuser runhidden;


Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: postinstall skipifsilent;

; Install Node
Filename: "{sys}\msiexec.exe"; Parameters: "/passive /i ""{app}\{#NODE64}""";

; 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;

; Add System Service
Filename: "{app}\{#NSSM64}"; Parameters: "install {#MyAppShortName} ""{pf64}\nodejs\node.exe"" ""{app}\ecom\angular\server\main.js"""; Flags: runhidden;
Filename: "{sys}\net.exe"; Parameters: "start {#MyAppShortName}"; Flags: runhidden;

;Filename: "{cmd}"; Parameters: "/C set PATH=%PATH%;{app}\mongodb\bin"; Flags: runascurrentuser waituntilterminated;
; Run MongoDB mongod command
;Filename: "{cmd}"; Parameters: "/K mongod >> ""{app}\mongo_logfile.txt"" 2>&1"; Flags: postinstall waituntilterminated runascurrentuser;


[UninstallRun]
Filename: "{app}\{#NSSM64}"; Parameters: "remove {#MyAppShortName} confirm"; Flags: runhidden;
Filename: "{app}\{#NSSM64}"; Parameters: "stop {#MyAppShortName}"; Flags: runhidden;

; Removes System Service
;Filename: "{sys}\net.exe"; Parameters: "stop {#MyAppShortName}"; Flags: runhidden;
;Filename: "{app}\{#NSSM64}"; Parameters: "remove {#MyAppShortName} confirm"; Flags: runhidden;
;Filename: "{sys}\net.exe"; Parameters: "stop {#MyAppLCShortName}"; Flags: runhidden;
;Filename: "{pf64}\nodejs\node.exe"; Parameters: "{app}\bin\windows-service-installer.js remove"; Flags: runhidden;


[Code]
procedure DebugOutput(Msg: string);
begin
  Log('Debug: ' + Msg);
end;

[Code]

windows-services
1个回答
0
投票

问题出在 Inno Setup 和 nssm 的组合上,它们都用双引号转义双引号。这使得需要多个双引号。

解决方案:

; Add System Service
Filename: "{app}\{#NSSM64}"; Parameters: "install {#MyAppShortName} ""{pf64}\nodejs\node.exe"" """"""{app}\ecom\angular\server\main.js"""""""; Flags: runascurrentuser runhidden;

参考:这个 StackoverFlow 问题


对于日志错误和标准资源,您可以设置 nssm 的附加选项

Filename: "{cmd}"; WorkingDir: "{app}"; Parameters: "/c nssm set {#MyAppShortName} AppStdout ""{app}\myServiceLog-stdOut-log.txt"""; Flags: runascurrentuser runhidden;
Filename: "{cmd}"; WorkingDir: "{app}"; Parameters: "/c nssm set {#MyAppShortName} AppStderr ""{app}\myServiceLog-stdErr-log.txt"""; Flags: runascurrentuser runhidden;
Filename: "{cmd}"; WorkingDir: "{app}"; Parameters: "/c nssm set {#MyAppShortName} AppNoConsole 1"; Flags: runascurrentuser runhidden;
© www.soinside.com 2019 - 2024. All rights reserved.