【问题标题】:Service Fabric Package Activation ErrorService Fabric 包激活错误
【发布时间】:2018-03-01 23:12:19
【问题描述】:

得到以下错误

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 没有 bash,因此认为 windows 集群在 entyPoint.sh 脚本上失败了。 Linux 集群显然越过了这一点,并且在初始化代码中的某个地方失败了,但仍然找不到在哪里。我添加了

 <ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048"/>

并从 linux 机器上下载了所有日志,但从那里的控制台看不到任何东西。

Error event: SourceId='System.Hosting', 

Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation.The service host terminated with exit code:134

启动类的样子

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();
                        }))
        };
    }
}

程序.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();
            }
        }
    }
}

我无法找到有关错误的详细信息,也无法在服务结构环境中调试任何内容,因为它们无法运行。任何帮助表示赞赏!

我已经运行 PerfView 并找到了与包激活相关的事件,但其中没有提示实际问题是什么。即使没有人知道问题出在哪里,只是一些获得更多信息的技术帮助也会很棒!

另一件看起来很奇怪的事情是,即使我注释掉 Main() 方法中的所有代码,我仍然会得到完全相同的错误。几乎就像它在框架 dll 或类似的东西上出现之前就失败了,但一切都是 .netcore2 并且我已经在带有服务结构的机器上安装了运行时

【问题讨论】:

  • 你的启动脚本包含什么?
  • 什么是options.Host。尝试强制服务结构分支运行

标签: .net asp.net-core microservices azure-service-fabric service-fabric-stateless


【解决方案1】:

显然,这是因为 Linux 和 Windows 中的行尾不同造成的。 Windows 系统使用 CR+LF,而 Unix 和类 Unix 系统使用 LF。

要解决您的问题,请执行

sed -i -e 's/\r$//' entrypoint.sh

如果有任何其他 .sh 文件在 sed -i -e 's/\r$//' *.sh 有帮助时,您可能需要这样做。

然后继续使用 Service Fabric 集群的东西!

人们还玩unix2dosdos2unix 之类的东西来解决这些问题,here 列出了充足的替代方案。

【讨论】:

    猜你喜欢
    • 2016-10-19
    • 2018-01-25
    • 2019-07-31
    • 2017-06-17
    • 2017-04-17
    • 2016-09-30
    • 1970-01-01
    • 2018-12-05
    • 2019-10-28
    相关资源
    最近更新 更多