I have a Service Fabric application that was written in .Net Core. It runs just fine on a local windows SF Cluster. It consists of a single stateless service with no web component.
I'm now trying to deploy it to a Linux SF Cluster. I was able to get SF running in Docker, using the service-fabric-onebox instance.
I used the entryPoint.sh file you get from using the azuresfcsharp yeomen template, and changed the EntryPoint Program node in the ServiceManifest.xml file. I'm also compiling my project using the dotnet cli and the -r ubuntu.16.04-x64 switch.
Now, when I try to deploy to my SF Cluster, I get
Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation.The service host terminated with exit code:32512
Any ideas?
I finally figured it out. I'll post the answer here, but I'll also go ahead and run through all the steps of getting a Service Fabric project developed in windows to run on Linux.
In an SF project's ServiceManifest.xml, there is a EntryPoint/ExeHost/Program node. In windows, this points to the exe generated by msbuild. Not so much in Linux.
npm i -g yo
npm i -g generator-azuresfcsharp
yo azuresfcsharp
When the generator runs, it'll give you a SF project folder and a c# project folder. Go to the SF project/service name folder/Code. In that folder will be two files named entryPoint.sh and dotnet-include.sh
You need to add those to your project, and set them to Content and Copy Always.
Lastly, in the ServiceManifest.xml, change the EntryPoint/ExeHost/Program node to entryPoint.sh
Compiling with Visual Studio won't work because you need to target the linux runtime.
Side Note - Before you compile, you need to understand how a Service Fabric package is laid out. The best way to to right click the SF project in Visual Studio, click package, go to the SF project folder in explorer, go to pkg, and look there.
In a console window, cd to the folder that has the csproj file of the service you're building. Let's assume you're building your deployment package in a folder called pkg
in the root of your solution. So run:
dotnet publish -o ..\pkg\YourServicePkg\Code -r ubuntu.16.04-x64
Note - the folder in your pkg HAS to end with Pkg.
Other Note - Look here for a list of runtimes you can target. I just happen to be using unbuntu. Runtime Identifiers
Lastly, to round out your deployment package, you'll need the ApplicationManifest.xml file in the root of your package folder, the ServiceManifest.xml file from your service project, and the Config folder from your service project. The service project files can be found in PackageRoot
So you'll have:
pkg
|
-> ApplicationManifest.xml
-> YourServicePkg
|
-> ServiceManifest.xml
-> Code (This is where you targeted dotnet publish)
-> Config
Now you need somewhere to run it locally. I used docker. Here is the link for the full setup instructions, but I'll go over the basics here.
First off, you'll need to update your docker deamon config with the following settings:
{
"ipv6": true,
"fixed-cidr-v6": "2001:db8:1::/64"
}
Then, pull the image.
docker pull servicefabricoss/service-fabric-onebox
You'll need to open port 19080 and 19000 with
-p 19080:19080 -p 19000:19000
If you've been using the Service Fabric Local Cluster Manager in windows, you'll need to right click the icon in your system tray and click Remove Cluster. Then when that finishes, you need to exit. You HAVE to remove the cluster, otherwise weird things happen.
Once the docker image is started, open it's bash and run ./setup.sh
, followed by ./run.sh
Once SF is running on docker and you can go to localhost:19080, it's time to deploy with powershell.
First, let's test our package to see if it's valid.
Test-ServiceFabricApplicationPackage .\pkg\
If that works, let's deploy
Connect-ServiceFabricCluster localhost:19000
Register-ServiceFabricApplicationType -ApplicationPathInImageStore YourService
Remove-ServiceFabricApplicationPackage -ImageStoreConnectionString fabric:ImageStore -ApplicationPackagePathInImageStore YourService
New-ServiceFabricApplication -ApplicationName fabric:/YourService -ApplicationTypeVersion 1.0.0 -ApplicationTypeName YourServiceType
Your application should start in Linux.
So here's what got me, and resulted in the exit code:32512 error.
I am using github, and apparently, line ending style is set to windows. So when I pulled it down on another computer, the line endings were changed from LF to CR LF.
To fix this, I had to open the effected files in Notepad++ and click Edit-> EOL Conversion -> Unix (LF).
I had to do this on ApplicationManifest.xml, all the ServiceManifest.xml files, and all the entryPoint.sh and dotnet-include.sh files.