Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Topshelf window service giving Error 1053 when try to start the service

I have developed a windows service using Topshelf. it works fine locally. When i deployed to test and try to start the service, it is giving me the following error:

Error 1053: The service did not respond to the start or control request in a timely fashion.

The test server is running on Windows server 2012.

This is my service start and stop methods:

public void Start()
{
    _logProvider.Info("Service started.");

    StartScheduledJobs();
}

public void Stop()
{
    _scheduler.Shutdown(true);

    _logProvider.Info("Service stopped.");
}

private void StartScheduledJobs()
{
    try
    {
        _scheduler.Start();

         ScheduleDeleteJob();
    }
    catch (Exception ex)
    {
        _logProvider.Error("", ex);
    }
}

Can anyone help me what could be the reason with the solution please?

Thanks

like image 559
Mukil Deepthi Avatar asked Sep 08 '16 10:09

Mukil Deepthi


3 Answers

The problem is that you are starting the service's work in the Start() method.

This works fine during development, but when you install a service, the Service Control manager calls Start and waits 30 seconds for it to return - if it does, then the service is considered to have installed successfully.

Because you start your scheduled jobs, though, in the Start method, it doesn't return within that time, and you get this error.

The resolution is to start the work indirectly in Start and then return - start a dedicated thread to do it, or use a timer, there are lots of options.

like image 164
stuartd Avatar answered Oct 17 '22 22:10

stuartd


Here this issue has been resolved: https://github.com/Topshelf/Topshelf/issues/183

In a nutshell: your Start() method should return true when service starts.

like image 31
Eugene Rozhkov Avatar answered Oct 17 '22 21:10

Eugene Rozhkov


After trying every other solution without success I found a solution that solved my problem with the same error message.

public static int Main(string[] args)
{
    Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
    //...
}

Based on https://github.com/Topshelf/Topshelf/issues/473

like image 5
Danieboy Avatar answered Oct 17 '22 22:10

Danieboy