I have a handful of console apps installed as services running under topshelf and if I install and run manually they work fine. However none automatically start even though the startup type is set to Automatic.
The apps are configured as follows:
HostFactory.Run(x =>
{
x.Service<MyApp>(s =>
{
s.ConstructUsing(name => container.Resolve<MyApp>());
s.WhenStarted(tc => tc.Start());
s.WhenStopped(tc =>
{
tc.Stop();
container.Dispose();
});
});
x.RunAsLocalSystem();
x.StartAutomatically();
x.EnableServiceRecovery(rc => rc.RestartService(5));
});
The apps run under Win 2008 R2 and they are installed using a batch file executed as Admin. The batch file includes the following:
app.exe install --sudo
app.exe start
After executing the the batch file the services run as expected. However if I reboot they remain stopped.
The event log returns the same pair of events for each service:
Event 7000: The service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion.
Event 7009: A timeout was reached (30000 milliseconds) while waiting for the service to connect.
The only way to start the app after a reboot is to run app.exe start
from an elevated command prompt.
Any ideas?
OK i've fixed it. The service startup types were set to Automatic but i've changed them to Automatic (Delayed) and all now run properly on start-up.
Also i've modified the install batch files for future use:
app.exe install --delayed --sudo
app.exe start
Only a guess, but probably dependent on network services which might not be available.
The most likely answer is that it's taking too long for the container to get created and resolved during start up when other stuff is happening on the machine. When you do it manually, nothing else is vying for resources. Can you defer some of the work done in your container until after creation & start? You can also request more time, but I don't recall that API off the top of my head.
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