why the service control manager doesn't start my service

  • Thread starter Thread starter Jianwei Sun
  • Start date Start date
J

Jianwei Sun

Hi, all,

I have a question, and I hope to get some hints here..

I created a really simple service just to check why the service manager
doesn't start my service the second time if the first time failed..

I created an atl service through the wizard, and the only thing I do is
override the PreMessageLoop()...

HRESULT CAutoStartServiceModule::PreMessageLoop(int nShowCmd)
{
HRESULT hr = CAtlServiceModuleT<CAutoStartServiceModule,
IDS_SERVICENAME>::PreMessageLoop(nShowCmd);
if(FAILED(hr)) return hr;

//return a false here..
//log event here..
LogEvent(_T("Failed to start the service, should retry ...."));
return E_ABORT;
}


And in the service control panel, i set "Recovery options" as

First Failure: Restart the service..
Second Failure: Restart the service..
Subsequent Failure: Restart the service..

But the service was not restarted ...

I wonder maybe I miss something to report the right information back to
the service control manager..

Thanks for any help..

J.W.
 
I Jinwei,

see inline

Jianwei Sun said:
Hi, all,

I created a really simple service just to check why the service manager
doesn't start my service the second time if the first time failed..

I created an atl service through the wizard, and the only thing I do is
override the PreMessageLoop()...

HRESULT CAutoStartServiceModule::PreMessageLoop(int nShowCmd)
{
HRESULT hr = CAtlServiceModuleT<CAutoStartServiceModule,
IDS_SERVICENAME>::PreMessageLoop(nShowCmd);
if(FAILED(hr)) return hr;

//return a false here..
//log event here..
LogEvent(_T("Failed to start the service, should retry ...."));
return E_ABORT;
}

And in the service control panel, i set "Recovery options" as

First Failure: Restart the service..
Second Failure: Restart the service..
Subsequent Failure: Restart the service..

Recover options are only relevant if your service executable crashes, not
because of any HRESULTs which might lead to ending a process. If a process
is just ending by leaving all thread functions that is pretty OK for the
service control manager.

You could try something like int *p = NULL; *p = 42; that should crash your
service and the restart should occur after the configured time interval.
Defaults to 1 minute IIRC.
 
Thanks, SvenC,

That definitely help, it seems that I may have to write some watchdong
service to watch the state of my service..

Thanks agian,

Jianwei
 
Hi Jinwei,

Jianwei Sun said:
Thanks, SvenC,

That definitely help, it seems that I may have to write some watchdong
service to watch the state of my service..

Why would you? Just change the logic how your service starts. Why do you
have any logic in your service that ends the process? Just start it up and
never shut down unless the service control manager gives you a stop signal.
If you think there is some situation where your service should not do
anything or is in an error state than try to recover within your running
service process. When something goes so wrong that your process crashes the
service control manager will restart your service (depending on the Recovery
options you chose). The service control manager is your watch dog.
 
Got it, thanks again..
SvenC said:
Hi Jinwei,



Why would you? Just change the logic how your service starts. Why do you
have any logic in your service that ends the process? Just start it up and
never shut down unless the service control manager gives you a stop signal.
If you think there is some situation where your service should not do
anything or is in an error state than try to recover within your running
service process. When something goes so wrong that your process crashes the
service control manager will restart your service (depending on the Recovery
options you chose). The service control manager is your watch dog.
 
Back
Top