Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Service Fabric SetupEntryPoint

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 "mysetup.bat" file that has the NET USE command that setups up the connection with my Azure Files share. However, I'm getting the following vague errors:

Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:SetupEntryPoint'. There was an error during CodePackage activation.The service host terminated with exit code:1

Anybody tried this before? Or at least any tips on how to get more information than the super helpful "Exit code:1"?

like image 319
emseetea Avatar asked Jan 23 '17 16:01

emseetea


2 Answers

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.

like image 62
emseetea Avatar answered Sep 29 '22 11:09

emseetea


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

like image 35
Erick B Avatar answered Sep 29 '22 12:09

Erick B