简体   繁体   English

Topshelf:成功安装服务后,install命令不会返回

[英]Topshelf: install command does not return after successfully installing the service

NOTE: I'm not doing anything similar to Topshelf installer requires me to press enter twice - why? 注意:我没有做任何与Topshelf相似的安装程序要求我按两次输入 - 为什么?

Service class (interesting parts): 服务类(有趣的部分):

public class ServiceCore
{
    public ServiceCore(ServiceRuntimeConfiguration serviceRuntimeConfiguration)
    {
        _runningTasks = new List<Task>();
    }

        public bool Start(HostControl hostControl)
        {
            _hostControl = hostControl;
            _messageProcessor.Start(); // Starts a System.Threading.Tasks.Task
            StartListener(); // starts a System.Threading.Tasks.Task
            return true;
        }
}

Program.cs: Program.cs中:

Host host = HostFactory.New(configurator =>
{

configurator.UseNLog();

// Configure core service
configurator.Service<ServiceCore>(svc =>
{
    svc.ConstructUsing(theService => new ServiceCore(_serviceRuntimeConfiguration));
    svc.WhenStarted((svc, hostControl) => svc.Start(hostControl));
    svc.WhenStopped((svc, hostControl) => svc.Stop(hostControl));
});

// Configure recovery params
configurator.EnableServiceRecovery(recoveryConfigurator =>
{
    recoveryConfigurator.RestartService(0);
    recoveryConfigurator.OnCrashOnly();
    recoveryConfigurator.SetResetPeriod(1);
});

// Execute HostConfigurator
host.Run();
}

The Problem 问题

When I do this: 当我这样做:

MyService.exe install --manual --localsystem

The service installs fine, but the command never returns: 该服务安装正常,但该命令永远不会返回:

Running a transacted installation. 运行事务安装。

Beginning the Install phase of the installation. 开始安装的安装阶段。 Installing service NotificationEngine.Main... Service NotificationEngine.Main has been successfully installed. 安装服务NotificationEngine.Main ...服务NotificationEngine.Main已成功安装。

The Install phase completed successfully, and the Commit phase is beginning. 安装阶段成功完成,提交阶段正在开始。

The Commit phase completed successfully. 提交阶段成功完成。

The transacted install has completed. 事务处理安装已完成。

^C (I have to press CTRL+C) ^ C(我必须按CTRL + C)

What should I do for the install command to complete and then return? 我该怎么做才能使install命令完成然后返回?

NOTE The same behaviour is observable if I run help (ie help displays but the command does not return): 注意如果我运行帮助(即帮助显示但命令不返回),则可以观察到相同的行为:

MyService.exe help

Generally this means you don't release control of some resource and the process can't cleanly exit. 通常,这意味着您不释放某些资源的控制权,并且该流程无法彻底退出。 However, this stuff is complicated, so it's hard to say for sure. 然而,这些东西很复杂,所以很难说肯定。

A few things I would try 我会尝试一些事情

  • What happens when you execute MyService start after an install/CTRL+C? 安装/ CTRL + C后执行MyService start时会发生什么? I'm assuming it also blocks since help does. 我假设它也会因为帮助而阻塞。
  • Check logging, do you have any enabled? 检查日志记录,你有没有启用? Is there file contention or permissions issues? 是否存在文件争用或权限问题?
  • What else does your Main() entry point do? 您的Main()入口点还有什么作用? Is it doing something that after host.Run() ? 它是在host.Run()之后做的吗? Your code above makes it looks like you're calling it from within the construction of that object, but I assume it's bad cut-n-pasting. 上面的代码使得它看起来就像你在该对象的构造中调用它,但我认为它是糟糕的切割粘贴。
  • Make sure you aren't initializing resources before the ConstructUsing and When* callbacks are fired. 确保在ConstructUsingWhen*回调被触发之前没有初始化资源。

After this, I would take this to our mailing list at https://groups.google.com/forum/#!forum/topshelf-discuss . 在此之后,我会将此信息发送到https://groups.google.com/forum/#!forum/topshelf-discuss上的邮件列表。

ServiceCore : ServiceBase ServiceCore:ServiceBase

The type T specified in the configurator.Service should subclass ServiceBase. 在configurator.Service中指定的类型T应该是ServiceBase的子类。

This fixed the problem for a service that would install fine but hang on the last step of install/uninstall. 这解决了安装正常但挂在安装/卸载的最后一步的服务的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM