PeterKottas / DotNetCore.WindowsService

Simple library that allows one to host dot net core application as windows services. Perfect solution to power micro-services architecture.
MIT License
568 stars 150 forks source link

Service did not respond to the start or control request in a timely fashion #109

Open pmunshi007 opened 5 years ago

pmunshi007 commented 5 years ago

I know this issue was raised before but currently I am also facing the same issue and I have tried all the solutions provided in #13 but no luck. Most annoying part here is the code base is same in master branch and my current branch. I just added few arguments to pass while running the program however the code to install/start/stop/uninstall service is the same. I am able to install and run service from master branch code base. But I am getting below error while trying to start service via command-line in my current branch. I am running this program in administrator terminal and also my basedirectory path does not contain space.

System.InvalidOperationException: Cannot start service testService on computer '.'. ---> System.ComponentModel.Win32Exception: The service did not respond to the start or control request in a timely fashion
         --- End of inner exception stack trace ---
         at System.ServiceProcess.ServiceController.Start(String[] args)
         at PeterKottas.DotNetCore.WindowsService.ServiceRunner`1.StartService(HostConfiguration`1 config, ServiceController sc)
         at PeterKottas.DotNetCore.WindowsService.ServiceRunner`1.UsingServiceController(HostConfiguration`1 config, Action`2 action)
         at PeterKottas.DotNetCore.WindowsService.ServiceRunner`1.Run(Action`1 runAction)
info: *.Service.Program[0]
      Return value from Run function -1

Even If I try to run the installed process from user interface it gives me below error.

windows could not start the service on local computer
error 1053 the service did not respond to the start or control request in a timely fashion

I am using 2.0.8 version of PeterKottas.DotNetCore.WindowsService library. What could be the reason here?

pmunshi007 commented 5 years ago

I am having same error with the latest version also 2.0.9 version of PeterKottas.DotNetCore.WindowsService library.

andreibulatov commented 5 years ago

I have this trouble too

upd solution I rewrote Main method, replaced all slowly reflection before ServiceRunner<SomeService>.Run(config =>{

ka4ep commented 5 years ago

Quite a common problem. My solution was to implement an own descendant of MicroService class where I've started a RunOnceTimer with all the initialization, IoC with assembly scanning, Akka, Nancy in a callback method. Not before or during Run(). Basically, you start a separate thread (like timer) and immediately tell Windows you're all done loading.

kalimist123 commented 5 years ago

Im having this problem too. @Apostol59 could you elaborate on your solution?

andreibulatov commented 5 years ago

@kalimist123, no problem, bro. I had di container configuration in method main, container cofiguration was be relocated in OnStart.

Main method must contains minimum of operations before OnStart.

//from example
void Main()
{
//old di configuration
ServiceRunner<ExampleService>.Run(config =>
{
    var name = config.GetDefaultName();
    config.Service(serviceConfig =>
        {
            serviceConfig.ServiceFactory((extraArguments, microServiceController) =>
        {
            return new ExampleService();
        });
        serviceConfig.OnStart((service, extraArguments) =>
        {
//now di configuration
            Console.WriteLine("Service {0} started", name);
            service.Start();
        });
...
}
}
kalimist123 commented 5 years ago

@Apostol59 thank you

justintoth commented 5 years ago

I was running into this error as well, however I was hitting it immediately when starting the service, it wasn't waiting 30 seconds. The issue was that I was using Network Service instead of Local System to run the windows service, must have been some sort of permissions issue...

sagar-patel-sls commented 5 years ago

@Apostol59

I am having same error with the latest version of PeterKottas.DotNetCore.WindowsService library. Above your solution didn't work for me

can you please help me..

andreibulatov commented 5 years ago

@sagar-patel-sls Hi, I'm not a maintainer. May be @PeterKottas can help you, but, will be need more details, I think)

sagar-patel-sls commented 5 years ago

Hii @PeterKottas

I am having same error with the latest version of PeterKottas.DotNetCore.WindowsService library. Above your solution didn't work for me

can you please help me..