Windows could not start service on Win Server 2008 R2 SP1 (Error 1053)

折月煮酒 提交于 2020-02-20 06:49:41

问题


This issue seems to be widely discussed, but I have problems with finding the solution in my particular case.

My service is set up to be running under Local System account. On my first machine with Windows 7 SP1 (64-bit) installed, everything works as expected. But, just after I try to start the service on my second machine with Windows Server 2008 R2 SP1 (64-bit), not even a second passes, and I'm facing this annoying error:

Windows could not start the ProService service on Local Computer
Error 1053: The service did not respond to the start or control request in a timely fashion

The System Log shows 2 entries:

The ProService service failed to start due to the following error: 
The service did not respond to the start or control request in a timely fashion.

and:

A timeout was reached (30000 milliseconds) while waiting for the ProService service to connect.

The implementation looks following:

Program.cs:

static void Main()
{
    AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
    ServiceBase.Run(new ServiceBase[] { new ProService() });
}

static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    if (e != null && e.ExceptionObject != null)
    {
        Logger.Record(e.ExceptionObject);
    }            
}

ProService.cs:

public ProService()
{
    InitializeComponent();
}

protected override void OnStart(string[] args)
{
    try
    {
        RequestAdditionalTime(10000);
        FireStarter.Instance.Execute();
    }
    catch (Exception e)
    {
        Logger.Record(e);
        throw;
    }            
}

The OnStart method is just starting a new thread, so it takes almost NO time load to execute. I used RequestAdditionalTime statement just in case - to reject this matter as a source of my problem. In addition, as you can see, I'm handling all of the exceptions, but no exception is written to my custom service event log during the startup (btw: logging is working on the first win7 machine). How to investigate what's going on ?


回答1:


I've figured out what was going on in a few steps:

  1. I've written console application - wrapper for what is basically done in OnStart method from service.
  2. I've executed console application - application started normally.
  3. I've copied content of service configuration file to console application configuration file.
  4. I've executed console application once again - application aborted silently and immediately (surprisingly similar to our service behavior, something is wrong).
  5. I've compared 2 configs - from service, and original from console application. As a result I've found some differences. Among others, there was such an entry - the source of the problem (after removal, everything works):

    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    

So basically I had out of date configuration file. Previously service was compiled under .NET 4.5, then I've changed the framework to 4.0 and deployed files to the server, but left the previous configuration file (I've changed the target framework because my development machine has .NET 4.5 while server does not). I wouldn't have thought the shown lines would hide all problems without any reasonable information, which could help to track the mess.




回答2:


Check for missing dependencies/DLLs.

If you haven't already done so, allow your service to be invoked as a regular application (a great technique for long-term debugging) and see if it starts properly on your Windows 2008 machine.

If works that way, then there may be an issue with running in the LocalSystem account. Move on to starting your application from a command prompt running in the LocalSystem account (example setup here).




回答3:


I tried the following fix which was provided at this link

  1. Click Start, click Run, type regedit, and then click OK.

  2. Locate and then click the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control

  3. In the right pane, locate the ServicesPipeTimeout entry.
    Note If the ServicesPipeTimeout entry does not exist, you must create it. To do this, follow these steps:
    a. On the Edit menu, point to New, and then click DWORD Value.
    b. Type ServicesPipeTimeout, and then press ENTER.
  4. Right-click ServicesPipeTimeout, and then click Modify.
  5. Click Decimal, type 60000, and then click OK.
    This value represents the time in milliseconds before a service times out.
  6. Restart the computer.

But still I had the problem to start the service.

The fix which worked for me was,

  1. Go the services.msc
  2. Double click the service which you are trying to start.
  3. Take the Logon Tab
  4. Changed Log on as: to Local System account.
  5. Tried starting the service after this change.(Still gave the 1053 error)
  6. Took the Log on tab again, changed it to Network Service (gave a random new password)
  7. Tried starting the service again.(The service started perfectly)



回答4:


I tried the below steps. It worked like a charm.

1.Go the services.msc 2.Double click the service which you are trying to start. 3.Take the Logon Tab 4.Changed Log on as: to Local System account. 5.Tried starting the service after this change.(Still gave the 1053 error) 6.Took the Log on tab again, changed it to Network Service (gave a random new password) 7.Tried starting the service again.(The service started perfectly)

But I just want to know what will be the issue.




回答5:


After installing service, i have to gave full control permission(Everyone) for installation folder. Then, my service will started perfectaly.



来源:https://stackoverflow.com/questions/14121079/windows-could-not-start-service-on-win-server-2008-r2-sp1-error-1053

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!