Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

topshelf

NOTE: I'm not doing anything similar to Topshelf installer requires me to press enter twice - why?

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:

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.

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)

What should I do for the install command to complete and then return?

NOTE The same behaviour is observable if I run help (i.e. help displays but the command does not return):

MyService.exe help
like image 670
Sudhanshu Mishra Avatar asked Jan 22 '16 04:01

Sudhanshu Mishra


1 Answers

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? 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? Is it doing something that after 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.

After this, I would take this to our mailing list at https://groups.google.com/forum/#!forum/topshelf-discuss.

like image 195
Travis Avatar answered Sep 21 '22 23:09

Travis