Search code examples
windows-serviceswindows-server-2008-r2windows-server-2012topshelf

Automatic services do not start


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?


Solution

  • 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.