I have three windows services all created using TopShelf. All three are configured very similarly, so I updated my three projects to use a shared framework type project.
public void StartService()
{
HostFactory.New(x =>
{
x.Service<IService>(s =>
{
s.ConstructUsing(() =>_service);
s.WhenStarted(poller => poller.Start());
s.WhenStopped(poller => poller.Stop());
});
x.EnableShutdown();
x.RunAsLocalSystem();
x.SetDescription(description);
x.SetDisplayName(display);
x.SetServiceName(name);
x.StartAutomatically();
x.OnException(ex =>
{
ExceptionManager.Publish(ex);
});
x.EnableServiceRecovery(rc =>
{
rc.RestartService(1);
rc.RestartService(1);
rc.RestartService(1);
});
}).Run();
}
To deploy these services there is a step in Octopus that runs for each service. The step does the following: (All commands are run using powershell)
- D:\myservicename.exe stop
- D:\myservicename.exe uninstall
- Deploy new code to folder destination
- D:\myservicename.exe install
- D:\myservicename.exe start
This continues to work for two of my services. For the third service, the commands take effect but never seems to finish. I've run these manually on the server in powershell and the command line and I'm getting the same issue. The command being run takes effect but never finishes. I have to Ctrl+C to stop it.
I thought the service might have been stuck some how, so I've tried uninstalling it using sc delete and then restarting the box, but this had no effect. All three services are running without error when they are started.
Before this change all three services worked and deployed without issue. When I put the start service method back into the main method of the service that is giving me trouble, it works.
Has anyone encountered this before? Is there a way I can tell the command to wait until it gets the correct response? Or is there a way to get more details, if there is actually an error occurring here?