问题
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
回答1:
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.
回答2:
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.
回答3:
I'm not sure the error message you're receiving is the actual error. How to debug:
- Verify with logs that start method begins. Note: make sure log path is specific, since windows service may be starting under different account. If you have something like
${LOCALAPPDATA}
in your log file appender path then you'll be confused why you don't any logs in the path you've been using during development. - Verify that more than 30 seconds elapsed before
StartScheduledJobs()
finishes. - If your code in Start is not executing, then something in
static void main(args [])
is happening before the window's service starts that is causing this issue. This issue may only happen when doing MyService.exe start. I recommend removing code prior to whereHostFactory
wraps your service.
Note: TopShelf has log4net plugin you can install to trace where the exception is occuring (http://docs.topshelf-project.com/en/latest/configuration/logging.html).
回答4:
I was in the same situation... After two days of debugging one colleague saw that my path to quartz_jobs.xml in App.config was incorrect.
incorrect
<add key="quartz.plugin.jobInitializer.fileNames" value="quartz_jobs.xml" />
correct
<add key="quartz.plugin.xml.fileNames" value="~/quartz_jobs.xml" />
Cheers!
来源:https://stackoverflow.com/questions/39388014/topshelf-window-service-giving-error-1053-when-try-to-start-the-service