By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

why the service control manager doesn't start my service

P: n/a
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.
Sep 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I Jinwei,

see inline

"Jianwei Sun" <js***********@gmail.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
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.

--
SvenC
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.

Sep 18 '06 #2

P: n/a
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

SvenC wrote:
I Jinwei,

see inline

"Jianwei Sun" <js***********@gmail.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>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.

--
SvenC
>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.

Sep 18 '06 #3

P: n/a
Hi Jinwei,

"Jianwei Sun" <js***********@gmail.comwrote in message
news:Ol**************@TK2MSFTNGP04.phx.gbl...
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.

--
SvenC
Thanks agian,

Jianwei

SvenC wrote:
>I Jinwei,

see inline

"Jianwei Sun" <js***********@gmail.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl. ..
>>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.

--
SvenC
>>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.
Sep 19 '06 #4

P: n/a
Got it, thanks again..
SvenC wrote:
Hi Jinwei,

"Jianwei Sun" <js***********@gmail.comwrote in message
news:Ol**************@TK2MSFTNGP04.phx.gbl...
>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.

--
SvenC
>Thanks agian,

Jianwei

SvenC wrote:
>>I Jinwei,

see inline

"Jianwei Sun" <js***********@gmail.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl.. .
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.

--
SvenC

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.
Sep 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.