Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kharlamov opened this issue Mar 23, 2017 · 10 comments
Closed

Comments

@kharlamov
Copy link

I am having issues starting my service on Windows Server 2008 R2.

Installed it via
dotnet .\MyWindowsServiceApplication.dll action:install name:MyWindowsServiceApplication displayName:MyWindowsServiceApplication description:"My windows service application."

And it shows up, when i try to start it I instantly get Error 1053 service did not respond to the start or control request in a timely fashion

When I run in manually through powershell via "dotnet .\MyWindowsServiceApplication.dll action:start" I get the following error through my logging around the ServiceRunner.Run:

2017-03-23 18:51:16.1887 ERROR Program - System.InvalidOperationException: Cannot start service MyWindowsServiceApplication 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.ServiceRunner1.StartService(HostConfiguration1 config, ServiceController sc) at PeterKottas.DotNetCore.WindowsService.ServiceRunner1.ConfigureService(HostConfiguration1 config) at PeterKottas.DotNetCore.WindowsService.ServiceRunner1.Run(Action1 runAction)

I can't tell what is going on as I get no other exception anywhere, any ideas?

I have managed to get this running locally on my computer which is the annoying part, just not on the server.

@PeterKottas
Copy link
Owner

Hey mate. 2 things come to mind afk. Try to omit "." when calling the service. Second thing to try would be running cmd/powershell as administrator. If that doesn't help, give this a read #12 . Tou might find some good points there. If nothing helps, I'll get back to to u tomorrow ;-)

@kharlamov
Copy link
Author

Yeah tried both of this things with no luck, I have simplified my app down to this, and again working locally not on the server:

        public static void Main(string[] args)
        {
            LogManager.Configuration = new XmlLoggingConfiguration(
                Path.Combine(AppContext.BaseDirectory, "NLog.config"), true);
            var logger = LogManager.GetCurrentClassLogger();

            Console.WriteLine("I am outputing.");
            ServiceRunner<MyWindowsServiceApplicationService>.Run(config =>
            {
                config.SetName("MyWindowsServiceApplication");
                var name = config.GetDefaultName();

                config.Service(serviceConfig =>
                {
                    serviceConfig.ServiceFactory(extraArguments => new MyWindowsServiceApplicationService());
                    Console.WriteLine("I am outputing.");

                    serviceConfig.OnStart((service, extraParams) =>
                    {
                        Console.WriteLine("I am not outputing.");
                    });

                    serviceConfig.OnStop(service =>
                    {
                    });

                    serviceConfig.OnError(e =>
                    {
                        Console.WriteLine(e);
                        logger.Error(e);
                    });

                });
            });
        }
    public class MyWindowsServiceApplicationService : IMicroService
    {

        public void Start()
        {

        }

        public void Stop()
        {
        }
    }

@PeterKottas
Copy link
Owner

I looks kinda similar to that issue I've send you previously. Try to get the int that the run method returns. It should be 0 if it works properly.

@PeterKottas
Copy link
Owner

Also get the app path this way : PlatformServices.Default.Application.ApplicationBasePath . That's what I use so it's worth trying.

@kharlamov
Copy link
Author

kharlamov commented Mar 23, 2017

Updated the path (They seem to be reporting the same path.), the run method is returning a -1.

Ill read through the other ticket see if i can find what is causing my issue and report back. The annoying thing is that the only thing in the Start is Console.WriteLine and that is where the exception stack trace is ending.

Update: There is a lot to sift through in the other ticket but so far I have discovered:

  • When I run it without action:run, I am getting all the correct output.
  • When I run with action:run through powershell I get the exception I mentioned, but I get it logged in nlog and the console from the OneError callback.
  • When I manually run the service directly through the Services Window it just gets the same 1053 error and I don't get no log file with the error.
  • When I manually run the service directly through the Services Window with File.WriteAllText no files are generated.
  • I have the same sdk on the server and locally, I am running dotnet publish for getting the code up to the server.
  • This is what the path to the executable is setup as C:\Program Files\dotnet\dotnet.exe C:\Program Files\My Windows Service\MyWindowsServiceApplication.dll action:run

Alright, thats all the information I have, sorry if I have been spamming you.

@kharlamov
Copy link
Author

kharlamov commented Mar 24, 2017

Amazing what a good nights sleep can do, I figured it out in my nightmares. The problem is the path and the command that gets generated.

Locally the command thats getting setup for the service is C:\Program Files\dotnet\dotnet.exe C:\Projects\MyWindowsServiceApplication\MyWindowsServiceApplication\bin\Debug\netcoreapp1.1\MyWindowsServiceApplication.dll action:run Notice no spaces to the DLL.

However on the server C:\Program Files\dotnet\dotnet.exe C:\Program Files\My Windows Service\MyWindowsServiceApplication.dll action:run has spaces in Program Files and My Windows Service which is making them invalid.

Is there anyway to fix this, could we wrap the second parameter in quotes in the action:install I am not sure if thats valid? From host = string.Format("{0} {1}", host, appPath); to host = string.Format("{0} \"{1}\"", host, appPath);:

host = string.Format("{0} {1}", host, appPath);

@PeterKottas
Copy link
Owner

Hi Andrew, don't worry, you're not spamming at all. On the contrary, good catch about the error! I'll make the change now and will upload new version so that you can give it a try. Will let you know once it's done

@PeterKottas
Copy link
Owner

Ok that's done and uploaded in v1.0.17 Let me know if it helps ;)

@kharlamov
Copy link
Author

Just tested up on the server works perfect, thank you so much 👍

@PeterKottas
Copy link
Owner

Awesome, glad we fixed it mate. Thanks for making this lib better! Spread the work and let me know if you need anything else ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants