RTC Forums
May 05, 2024, 10:03:31 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: RTC Service not starting - Error 1053  (Read 5613 times)
zsleo
RTC Expired
*
Posts: 80


« on: April 14, 2016, 06:07:07 AM »

RTC SDK 7.17; Win 10; Delphi XE

I am using the RTCWebserver sample code.

Everything as excepted when I run as a GUI but when I install and start the Service on Win 10 and Win Server 2008 R2 I get ERROR 1053 on both.

I have set Run as Administrator on both.

Permissions on  the applications and folders to have full rights.

The Service is running as LocalSystem

I am logged on to both as Administrator.

Any ideas where I am going wrong. This has been bugging me for a few days.

I have other non-RTC apps running as Services on both machines - including some RTC service apps compiled with Delphi 7 more than 2 years ago.

TIA
Logged
Kevin Powick
RTC Expired
*
Posts: 87


« Reply #1 on: April 14, 2016, 06:23:34 AM »

As you probably know, error 1053 is that your service application did not start for one reason or another.  Unfortunately, that's about all it tells you.

Some additional information would help diagnose the problem.

Did you check the Windows Event Viewer to see if any other application or system errors were logged at the same time your service failed to start?

When the service fails to start, does it happen immediately or after the full 30 second timeout on the start request?

Have you tried to run your code as a stand-alone foreground application? i.e. Not as a service?  Personally, I never install a service I've written without first knowing that it runs ok as a foreground application.
Logged

Linux is only free if your time is worthless
zsleo
RTC Expired
*
Posts: 80


« Reply #2 on: April 14, 2016, 07:05:53 AM »

That was a fast response... Smiley

Did you check the Windows Event Viewer to see if any other application or system errors were logged at the same time your service failed to start?
Yes I did. Message was too general:
The RTC WebServer service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.

When the service fails to start, does it happen immediately or after the full 30 second timeout on the start request?
After 30 seconds

Have you tried to run your code as a stand-alone foreground application?
Works perfectly as a non-service standalone GUI

Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: April 14, 2016, 09:38:25 AM »

Not sure if this is related, but here is a MSDN article about a problem starting a Service under the LocalSystem account on Windows 2003:
https://support.microsoft.com/en-us/kb/886695

In general, when there is any kind of a problem with RTC-based Projects, I recommend enabling full RTC Debug loggig (declare the RTC_DEBUG compiler directive for the Project) and re-building the Project (not just re-compiling), to make sure that ALL RTC units will be compiled with the RTC_DEBUG directive, then using the Log or xLog functions from the rtcLog unit to log all state changes in the Project. For example, when a Service is not starting, you could add a log entry for each event in Service and Server Modules (Win_Service and Server_Module units in the RTCWebServer Demo) to find out where it "hangs".

By default, when using Log and xLog functions from the rtcLog unit, a LOG sub-folder will be created in the same folder where your EXE file is, so you can find all the log files inside. Unless your EXE does NOT have write permissions in that folder, in which case the LOG sub-folder will be created in the Winows TEMP folder.

Best Regards,
Danijel Tkalcec
Logged
Kevin Powick
RTC Expired
*
Posts: 87


« Reply #4 on: April 14, 2016, 02:30:22 PM »

When the service fails to start, does it happen immediately or after the full 30 second timeout on the start request?
After 30 seconds

This usually means that your service .exe isn't crashing, but rather that it is "hanging".  Often this is a permissions issue or, with applications that use networking, a port issue of some type (binding, firewall, etc.).

Quote
Have you tried to run your code as a stand-alone foreground application?
Works perfectly as a non-service standalone GUI

It works perfectly on the same machine where it doesn't work as a service?  Even if does, when running on the desktop, it's running in the security context of the logged-on account (you said "administrator").  When running as a service, the security context is the LocalSystem account.  Have you tried changing the service to run under a specific account, such as Administrator?

If it does happen to run as as service when the service is set to run on the Administrator account, then you'll know it's a permissions issue.

However, regardless of the above, and as Danijel suggests in his reply, the next step is logging to find out exactly where the service hangs.  This should help you correct permission or port issues.
Logged

Linux is only free if your time is worthless
zsleo
RTC Expired
*
Posts: 80


« Reply #5 on: April 14, 2016, 10:12:07 PM »

Not at my device computer right now...

Kevin first:
I did run the service as administrator but with same result

Danijel:
I did do some more debugging/tracing late yesterday but not to the extent you suggest. Will do that in an hour. I did trace to the line of code in RTC source where service creation is failing. I will post in about an hour

Thank you both. This has been bugging  Grin me for too long
Logged
zsleo
RTC Expired
*
Posts: 80


« Reply #6 on: April 14, 2016, 11:24:58 PM »

DPR File Extract:

begin
  StartLog;

  if not IsDesktopMode(RTC_DATASERVICE_NAME) then // << Failss
  begin
    SvcMgr.Application.Initialize;
    SvcMgr.Application.CreateForm(TData_Server, Data_Server);
    SvcMgr.Application.CreateForm(TRtc_WebServer_1, Rtc_WebServer_1);
    SvcMgr.Application.Run;
  end
  else // << Enters this section and as a result the 30 second timeout is reported
  begin
    Forms.Application.Initialize;
    Forms.Application.Title := 'RTC WebServer';
    Forms.Application.CreateForm(TData_Server, Data_Server);
    Forms.Application.CreateForm(TWebServerForm, WebServerForm);
    if ParamCount > 0 then
      Data_Server.ServerHTTP.ServerPort := RtcString(ParamStr(1));
    Forms.Application.Run;
  end;
end.

rtcService.pas extract:

{$IFDEF WINDOWS}

function IsServiceStarting(const ServiceName: string): Boolean;
var
  Svc: Integer;
  SvcMgr: Integer;
  ServSt: TServiceStatus;
begin
  Result := False;
  SvcMgr := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
  if SvcMgr = 0 then
    Exit;
  try
    Svc := OpenService(SvcMgr, PChar(ServiceName), SERVICE_QUERY_STATUS);
    if Svc = 0 then
      Exit;
    try
      if not QueryServiceStatus(Svc, ServSt) then
        Exit;
      Result := (ServSt.dwCurrentState = SERVICE_START_PENDING); << Returns "False"; ServSt.dwCurrentState = 1
    finally
      ServSt.dwCurrentState      CloseServiceHandle(Svc);
    end;
  finally
    CloseServiceHandle(SvcMgr);
  end;
end;
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #7 on: April 15, 2016, 06:45:10 AM »

When using the TService class from Delphi to implement a Windows Service, the Name of your TService class descendant defines the Name of your Service, which is required to check if a Service is starting. This check is done from the IsServiceStarting function, which is called from the IsDesktopMode function, both requiring a Service Name as a parameter.

Now ... since you have changed the name of your TService class descendant (declared and implemented in the Win_Service unit) from TRtc_WebServer to TRtc_WebServer_1, you should also change the RTC_DATASERVICE_NAME constant (declared at the top of the Win_Service unit) from 'Rtc_WebServer' to 'Rtc_WebServer_1', because that constant is used from the DPR file in the IsDesktopMode function to check if your Project should start as a Windows Service or a normal Desktop Application.

Best Regards,
Danijel Tkalcec
Logged
zsleo
RTC Expired
*
Posts: 80


« Reply #8 on: April 15, 2016, 07:26:58 AM »

Grrrrrrr Embarrassed Embarrassed Embarrassed

I completely missed that!

THANK YOU Danijel
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.029 seconds with 18 queries.