Service Fabric SetupEntryPoint

坚强是说给别人听的谎言 提交于 2019-12-03 08:32:51

SetupEntryPoint is the right place to launch startup tasks. However, depending on what your startup tasks are you may need to specify a RunAsPolicy within the ApplicationManifest.xml.

Here is what I did:

Created a BAT file called 'setup.bat' and added it to my guest executable code folder. Inside this setup.bat file I am doing a NET USE statement to map a network drive to Azure Files share folder.

I added this:

<SetupEntryPoint>
  <ExeHost>
    <Program>setup.bat</Program>
    <Arguments></Arguments>
  </ExeHost>
</SetupEntryPoint>

to the ServiceManifest node.

<Policies>
     <RunAsPolicy CodePackageRef="Code" UserRef="SetupAdminUser" EntryPointType="All" />
</Policies>

into the ServiceManifestImport node...

Then added the following

  <Principals>
    <Users>
      <User Name="SetupAdminUser">
        <MemberOf>
          <SystemGroup Name="Administrators" />
        </MemberOf>
      </User>
    </Users>
  </Principals>

into the ApplicationManifest after the DefaultServices node. It's important that the Principals node comes after the DefaultServices node. Not sure why but it will make it impossible to deploy the application to your cluster.

In my case I solved the error: "CodePackageActivation:Code:SetupEntryPoint There was an error during CodePackage activation.The service host terminated with exit code:1"

by moving my setup script to a ps1 file and executing it from the MySetup.bat

So I ended it up with the following in my .bat and .ps1 files.

  1. In my MySetup.bat (the one you reference in the service manifest):

powershell.exe -ExecutionPolicy Bypass -Command ".\MySetup.ps1"

  1. In my MySetup.ps1 (add your own PowerShell script here):

netsh http add urlacl url=http://erick1.com:80/ user="NT AUTHORITY\NETWORK SERVICE"

How to debug:

Remote Desktop your Virtual Machine and go to "D:\SvcFab_App[YOUR SERVCE TYPE NAME HERE]\log" and check the .err and .out files. Don't forget to add to your service manifest.. the entire section would be:

<SetupEntryPoint>
  <ExeHost>
    <Program>MySetup.bat</Program>
    <WorkingFolder>CodePackage</WorkingFolder>
    <ConsoleRedirection FileRetentionCount="10"/>
  </ExeHost>
</SetupEntryPoint>

One last thing: In my case I had a special char in the .bat file that was not visible in Visual Studio and my setup was failing... I was only able to discovery it by reading the logs ( described above ). Don't be afraid of logs, it's usually one line in this case.

Thanks

I think it's because it runs as SYSTEM, which doesn't have a user profile to create the drive mapping in.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!