Service Fabric SetupEntryPoint

后端 未结 3 1485
后悔当初
后悔当初 2021-02-10 02:04

I have a Guest Executable that needs to access a shared drive (Azure Files). My guest executable is setup in of the ServiceManifest.xml. I\'ve tried adding a to launch a \"mys

相关标签:
3条回答
  • 2021-02-10 02:33

    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.

    0 讨论(0)
  • 2021-02-10 02:49

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

    0 讨论(0)
  • 2021-02-10 02:51

    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

    0 讨论(0)
提交回复
热议问题