.net 服务结构包激活错误
获取以下错误.net 服务结构包激活错误,.net,asp.net-core,microservices,azure-service-fabric,service-fabric-stateless,.net,Asp.net Core,Microservices,Azure Service Fabric,Service Fabric Stateless,获取以下错误 Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:EntryPoint'. There was an error during CodePackage activation.Service host failed to activate. Error:0x800700c1` 如果我在linux服务结构集群上尝试此操作,错误会发生一些变化。因此认为windows集群在enty
Error event: SourceId='System.Hosting',
Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation.Service host failed to activate. Error:0x800700c1`
如果我在linux服务结构集群上尝试此操作,错误会发生一些变化。因此认为windows集群在entyPoint.sh脚本上失败,因为windows没有bash。Linux集群显然已经克服了这一点,并在初始化代码中的某个地方失败了,但仍然找不到位置。我添加了
<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>
启动类看起来像
namespace MyApp
{
using System.Collections.Generic;
using System.Fabric;
using System.IO;
using System.Net.Http;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.ServiceFabric.Services.Communication.AspNetCore;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
/// <summary>
/// The FabricRuntime creates an instance of this class for each service type instance.
/// </summary>
internal sealed class MyApp : StatelessService
{
public MyApp(StatelessServiceContext context)
: base(context)
{
}
/// <summary>
/// Optional override to create listeners (like tcp, http) for this service instance.
/// </summary>
/// <returns>The collection of listeners.</returns>
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new ServiceInstanceListener[]
{
new ServiceInstanceListener(
serviceContext =>
new KestrelCommunicationListener(
serviceContext,
"ServiceEndpoint",
(url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting WebListener on {url}");
return new WebHostBuilder()
.UseKestrel()
.ConfigureServices(
services => services
.AddSingleton<ConfigSettings>(new ConfigSettings(serviceContext))
.AddSingleton<HttpClient>(new HttpClient())
.AddSingleton<FabricClient>(new FabricClient())
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseStartup<Startup>()
.UseUrls(url)
.Build();
}))
};
}
}
名称空间MyApp
{
使用System.Collections.Generic;
使用系统、织物;
使用System.IO;
使用System.Net.Http;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.Extensions.DependencyInjection;
使用Microsoft.ServiceFabric.Services.Communication.AspNetCore;
使用Microsoft.ServiceFabric.Services.Communication.Runtime;
使用Microsoft.ServiceFabric.Services.Runtime;
///
///FabriRuntime为每个服务类型实例创建此类的实例。
///
内部密封类MyApp:无状态服务
{
公共MyApp(无状态ServiceContext上下文)
:基本(上下文)
{
}
///
///可选覆盖,用于为此服务实例创建侦听器(如tcp、http)。
///
///听众的集合。
受保护的重写IEnumerable CreateServiceInstanceListeners()
{
返回新服务InstanceListener[]
{
新服务InstanceListener(
serviceContext=>
新红隼通信侦听器(
serviceContext,
“ServiceEndpoint”,
(url,侦听器)=>
{
ServiceEventSource.Current.ServiceMessage(serviceContext,$“在{url}上启动WebListener”);
返回新的WebHostBuilder()
.UseKestrel()
.配置服务(
服务=>服务
.AddSingleton(新配置设置(serviceContext))
.AddSingleton(新的HttpClient())
.AddSingleton(新的FabricClient())
.AddSingleton(serviceContext))
.UseContentRoot(目录.GetCurrentDirectory())
.UseServiceFabricIntegration(侦听器,ServiceFabricIntegrationOptions.None)
.UseStartup()
.useURL(url)
.Build();
}))
};
}
}
Program.cs
namespace MyApp
{
using System;
using System.Diagnostics;
using System.Threading;
using CommandLine;
using Microsoft.AspNetCore.Hosting;
using Microsoft.ServiceFabric.Services.Runtime;
internal static class Program
{
/// <summary>
/// This is the entry point of the service host process.
/// </summary>
private static void Main(string[] args)
{
var parser = new Parser(with =>
{
with.HelpWriter = Console.Out;
});
var options = new Options();
var result = parser.ParseArguments(args, options);
if (options.Host.ToLower() == MyAppConstants.ServiceFabricHost)
{
try
{
// The ServiceManifest.XML file defines one or more service type names.
// Registering a service maps a service type name to a .NET type.
// When Service Fabric creates an instance of this service type,
// an instance of the class is created in this host process.
ServiceRuntime.RegisterServiceAsync(
"WebServiceType",
context => new MyApp(context)).GetAwaiter().GetResult();
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(SnapNurse).Name);
// Prevents this host process from terminating so services keeps running.
Thread.Sleep(Timeout.Infinite);
}
catch (Exception e)
{
ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
throw;
}
}
else if (options.Host.ToLower() == MyAppConstants.SelfHost)
{
using (var host = WebHostBuilderHelper.GetWebHost(new WebHostBuilder(), options.Protocol, options.Port))
{
host.Run();
}
}
}
}
名称空间MyApp
{
使用制度;
使用系统诊断;
使用系统线程;
使用命令行;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.ServiceFabric.Services.Runtime;
内部静态类程序
{
///
///这是服务主机进程的入口点。
///
私有静态void Main(字符串[]args)
{
var parser=新的解析器(使用=>
{
with.HelpWriter=Console.Out;
});
var options=新选项();
var result=parser.ParseArguments(参数、选项);
if(options.Host.ToLower()==MyAppConstants.ServiceFabriHost)
{
尝试
{
//ServiceManifest.XML文件定义一个或多个服务类型名称。
//注册服务将服务类型名称映射到.NET类型。
//当服务结构创建此服务类型的实例时,
//该类的实例在此主机进程中创建。
ServiceRuntime.RegisterServiceAsync(
“WebServiceType”,
context=>newmyapp(context)).GetAwaiter().GetResult();
ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id,typeof(SnapNurse).Name);
//阻止此主机进程终止,以便服务继续运行。
Thread.Sleep(Timeout.Infinite);
}
捕获(例外e)
{
ServiceEventSource.Current.ServiceHostInitialization失败(例如ToString());
投掷;
}
}
else if(options.Host.ToLower()==MyAppConstants.SelfHost)
{
使用(var host=webhostbuilderhelp.GetWebHost(新的WebHostBuilder(),options.Protocol,options.Port))
{
host.Run();
}
}
}
}
我无法找到有关错误的详细信息,也无法在service fabric环境中调试任何内容,因为它们无法运行。欢迎提供帮助
我已经运行了PerfView并找到了与包激活相关的事件,但是没有提示实际的问题是什么。即使没有人知道问题是什么,也只需要一些技术帮助就可以获得更多信息
另一件看起来很奇怪的事情是,即使我注释掉Main()中的所有代码方法,我仍然得到完全相同的错误。几乎就像它在框架DLL或类似的东西上出现之前就失败了一样,但一切都是如此。netcore2和我将运行时安装在带有服务结构的机器上。显然,这是因为Linux和Windows中的行尾不同。Windows系统使用CR+LF while Unix和类Unix系统使用LF 要解决您的问题,请执行以下操作
sed -i -e 's/\r$//' entrypoint.sh
如果任何其他.sh
文件sed-i-e的/\r$/'*.sh
有帮助,您可能需要这样做
然后继续进行服务结构集群的工作
人们也会使用
unix2dos
和dos2unix
来解决这些问题,其中列出了大量的备选方案。启动脚本包含哪些内容?options.Host是什么。请尝试运行服务结构分支
sed -i -e 's/\r$//' entrypoint.sh