.Net Core Windows 服务未安装在 docker 容器中 [英] .Net Core windows service not installing in a docker container

查看:38
本文介绍了.Net Core Windows 服务未安装在 docker 容器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个非常奇怪的问题.我有一个 .net 核心 Windows 服务 (XYZ),其安装程序 (XYZ.msi) 是使用 Wix 创建的.我正在尝试在容器中安装此服务.该服务被安装,然后 Windows 尝试将其注册为服务,该服务超时给我以下信息":在系统事件日志中 由于以下错误,XYZ 服务 (XYZ) 服务无法启动:%%1053 等待 XYZ 服务 (XYZ) 服务连接时达到超时(30000 毫秒).,然后服务被卸载,这是预期的.

I am facing a very peculiar issue. I have a .net core windows service (XYZ) whose installer (XYZ.msi) is created using Wix. I am trying to install this service in a container. The service gets installed, then windows tries to register it as a service, the service times out giving me the following "information" in System Eventlogs The XYZ Service (XYZ) service failed to start due to the following error: %%1053 A timeout was reached (30000 milliseconds) while waiting for the XYZ service (XYZ) service to connect., and then the service gets uninstalled which is expected.

进一步当我检查应用程序事件日志时,我得到了这些

Further when I check the Application event logs I get these

产品:XYZ -- 错误 1920.服务 'XYZ' (XYZ) 未能启动.验证您是否有足够的权限来启动系统服务.

Windows Installer 安装了该产品.产品名称:XYZ.产品版本:0.0.0.0.产品语言:1033.制造商:......安装成功或错误状态:1603.

所以为了理解这些错误代码,我参考了错误代码 1603 和一些关于错误 1920 的其他链接,但由于这些链接非常通用,因此这些链接没有用.

So in order to understand these error codes I referred to Error Code 1603 and few other links on Error 1920, but since these are pretty generic, these links were of no use.

相同的服务在本地和不同的服务器上运行良好.

The same service is working fine locally and on a different server.

XYZ.msi所在容器内的文件夹有这些权限

The folder inside the container where XYZ.msi resides has these privileges

Path   : Microsoft.PowerShell.CoreFileSystem::C:app
Owner  : NT AUTHORITYSYSTEM
Group  : NT AUTHORITYSYSTEM
Access : BUILTINAdministrators Allow  FullControl
         BUILTINAdministrators Allow  268435456
         NT AUTHORITYSYSTEM Allow  FullControl
         NT AUTHORITYSYSTEM Allow  268435456
         NT AUTHORITYAuthenticated Users Allow  Modify, Synchronize
         NT AUTHORITYAuthenticated Users Allow  -536805376
         BUILTINUsers Allow  ReadAndExecute, Synchronize
         BUILTINUsers Allow  -1610612736
Audit  :
Sddl   : O:SYG:SYD:(A;ID;FA;;;BA)(A;OICIIOID;GA;;;BA)(A;ID;FA;;;SY)(A;OICIIOID;GA;;;SY)(A;ID;0x1301bf;;;AU)(A;OICIIOID;SDGXGWGR;;;AU)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)

此外,我假设所有安装都使用容器内的 ContainerAdministrator 帐户进行.

Also I am assuming that all the installation happen with ContainerAdministrator account inside the container.

现在我无法弄清楚问题是什么,如何进一步排除故障,如果是权限问题,我需要设置什么权限.在这方面的任何帮助将不胜感激.谢谢!

Now I am not able to figure out what the problem is, how to troubleshoot it further and if its a privileges issue what privileges do I need to set. Any help in this regard would be appreciated. Thanks !

dockerFile 看起来像这样

The dockerFile looks like this

FROM mcr.microsoft.com/windows/servercore:ltsc2019-amd64
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
WORKDIR /app
COPY [".","."]
RUN  ["powershell.exe", "./install.cmd"]

WiX .wxs 代码

WiX .wxs code

<Fragment>
    <ComponentGroup Id="ServiceComponents" Directory="APPLICATIONFOLDER">
      <Component Id="ServiceComponent" Guid="649E5964-126A-4DF5-95CF-CE7C2474E981">
        <File Id="xyz.exe" KeyPath="yes" Vital="yes" DiskId="1" Source="..xyzin$(var.Platform)$(var.Configuration)
etcoreapp3.1win-x64xyz.exe"/>
        <ServiceInstall
          Id="ServiceInstaller"
          Type="ownProcess"
          Vital="yes"
          Name="xyz"
          DisplayName="$(var.ProductName)"
          Description="$(var.Description)"
          Start="auto"
          Account="NT AUTHORITYLocalService"
          ErrorControl="normal" Interactive="no">
          <ServiceConfig DelayedAutoStart="yes" OnInstall="yes" OnReinstall="yes" />
          <util:ServiceConfig FirstFailureActionType="restart" SecondFailureActionType="restart" ThirdFailureActionType="none" ResetPeriodInDays="1" RestartServiceDelayInSeconds="0" />
        </ServiceInstall>
        <ServiceControl
          Id="ServiceController"
          Name="xyz"
          Start="install"
          Stop="both"
          Remove="both"
          Wait="yes" />
      </Component>
    </ComponentGroup>
  </Fragment>

推荐答案

虽然我还在调查.net core windows service 的行为,并且已经开启了另一个线程 此处 以 SO 社区对此的看法为例,问题似乎出在服务的实现方式上.这是一个奇怪的行为,但如果我不使用 .net core 3 附带的 Worker Template,而是像在 .net core 2.1 中使用 ServiceBase 和 IHostingLifetime 那样创建服务,它在所有环境中都可以正常工作.

Although I am still investigating the behavior of .net core windows service and has started another thread here to take the SO community's view on this, it appears that the problem was with the way the service was implemented. It's a strange behavior but if I do not use Worker Template that comes with .net core 3 and instead create the service like it was done in .net core 2.1 using ServiceBase and IHostingLifetime it works fine in all the environments.

这篇关于.Net Core Windows 服务未安装在 docker 容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆