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
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
MyService start
after an install/CTRL+C? I'm assuming it also blocks since help does. 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. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With