0

收到以下错误

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 并且我在带有服务结构的机器上安装了运行时

4

1 回答 1

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 集群的东西!

人们也会在这些问题上玩弄各种事情,这里列出了充足的unix2dos替代方案dos2unix

于 2017-09-25T05:55:55.913 回答