Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Oct 19, 2018 10:05 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: How make a service application quit and restart autom?
PostPosted: Sat Apr 29, 2006 10:24 am 
Offline
User avatar

Joined: Sat Apr 29, 2006 10:13 am
Posts: 239
Location: Sweden
Hi,
How do I end a service application so, that W2k considers it failing and restarts it (recovers it)?

It is setup for recovery 'Restart on failure' in Control Panel, i.e:

(W2k Control Panel) > Administrative tools > Services > double-click on myapplication > Tab Recovery
First failure: Restart the Service
Second failure: Restart the Service
Subsequent failure: Restart the Service
Restart service after: 1 minutes

Just ending the application is apparantly not constituting a failure. Can I end with some error code, or what is the way to go?

Thanks,
Lennart


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Apr 29, 2006 4:25 pm 
Offline
User avatar

Joined: Wed Sep 28, 2005 8:39 am
Posts: 9341
Location: St Augusta, MN
I don't think REALbasic has a way for you to do that. In fact, I can't find much in the way of documentation that explains how to report a failure via services entirely.

Just so I'm clear -- what you want is a way to quit the service as an error condition instead of graceful termination?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Apr 29, 2006 4:57 pm 
Offline
User avatar

Joined: Sat Apr 29, 2006 10:13 am
Posts: 239
Location: Sweden
Right. And the background is:
My program is a service application that uses an (USB-COMport) Serial port for listening for data.
Another user occasionally runs a program (Phone Connection Link) that somehow silently disables mine and it doesn't help to let a watch-dog timer do a Serial.Close and then Serial.Open.
I figured that if I can let the service stop (by exiting a DoEvents-loop) and then automatically restart, it might be functional again.
But I have not been able to let it restart automatically.

Btw, thanks for the useful ServiceManager that I happened to find.

Lennart


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Apr 29, 2006 5:13 pm 
Offline
User avatar

Joined: Wed Sep 28, 2005 8:39 am
Posts: 9341
Location: St Augusta, MN
Well, if calling Serial.Close and then Serial.Open doesn't cause the issue to go away, then I suspect that automatically restarting the service won't work either.

I'm not entirely certain, but I think the service needs to set the dwWin32ExitCode field to a non-zero value to designate that there's an error. I don't have the source code for the service functionality handy, but I think we set that based off the return value from the Run event. Try returning a non-zero value, and see if things change.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Apr 29, 2006 5:36 pm 
Offline
User avatar

Joined: Wed Sep 28, 2005 8:39 am
Posts: 9341
Location: St Augusta, MN
Yeah, I double-checked the codebase. We set the dwWin32ExitCode when you call Quit or when you return from the Run event. In either case, the value specified is put into the proper field and we alert the service manager of the exit code.

This makes me wonder if you have to return a specific error code to tell the service manager that it can restart the application or not...


Top
 Profile  
Reply with quote  
 Post subject: Re: How make a service application quit and restart autom?
PostPosted: Tue Apr 03, 2012 11:44 am 
Offline

Joined: Fri Nov 14, 2008 3:44 pm
Posts: 62
Resurrecting this thread, but I'm in a similar boat - I have certain conditions where I need the service application to quit but let Windows know that it's quitting via error, and needs to restart (as configured in Windows service setup). Does anyone have any information on making this happen?

Thanks!


Top
 Profile  
Reply with quote  
 Post subject: Re: How make a service application quit and restart autom?
PostPosted: Tue Apr 03, 2012 12:04 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Quit takes an argument that is the error code to pass to the OS. If you know the appropriate error code for the service you can call

Quit(X)


Top
 Profile  
Reply with quote  
 Post subject: Re: How make a service application quit and restart autom?
PostPosted: Tue Apr 03, 2012 12:19 pm 
Offline

Joined: Fri Nov 14, 2008 3:44 pm
Posts: 62
timhare wrote:
Quit takes an argument that is the error code to pass to the OS. If you know the appropriate error code for the service you can call

Quit(X)


do you know what X should be to tell Windows that the service has failed (and trigger the restarting)?


Top
 Profile  
Reply with quote  
 Post subject: Re: How make a service application quit and restart autom?
PostPosted: Tue Apr 03, 2012 1:32 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
I suspect that if you have the service set to auto restart, it doesn't matter what the error code is. The more I think of it, the more I suspect this is a Windows setup question, not an RB question.


Top
 Profile  
Reply with quote  
 Post subject: Re: How make a service application quit and restart autom?
PostPosted: Tue Apr 03, 2012 1:43 pm 
Offline

Joined: Fri Nov 14, 2008 3:44 pm
Posts: 62
timhare wrote:
I suspect that if you have the service set to auto restart, it doesn't matter what the error code is. The more I think of it, the more I suspect this is a Windows setup question, not an RB question.


Unfortunately, Quit() gracefully exits the service and doesn't call the Recovery settings (which Windows only accesses if the service fails).
As far as I can tell, sending any integer, positive, zero, or negative, through Quit() terminates the service gracefully.
I want to be able to terminate the service with an error, so that Windows recognizes it as a failure and attempts Recovery as defined in the service's properties.

The only way I can think to make this happen is to raise an unhandled error exception to terminate the service, which doesn't seem like it's the best way to do it.


Top
 Profile  
Reply with quote  
 Post subject: Re: How make a service application quit and restart autom?
PostPosted: Tue Apr 24, 2012 4:10 pm 
Offline

Joined: Fri Feb 27, 2009 12:18 am
Posts: 54
HI,

i handle this by creating another (monitor) service. its only function is to check a text file periodically for an exit code. if it finds it
then it restarts the service and writes eventlogs.

the main service then writes the file with its error reasons before it quits.

seems to work ok. in fact the monitor service monitors more than one service for me.


HTH,

Russ


Top
 Profile  
Reply with quote  
 Post subject: Re: How make a service application quit and restart autom?
PostPosted: Tue Apr 24, 2012 6:57 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
Probably a declare into the Win32 API for ExitProcess

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx

A non-zero exit code should cause the service to restart

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group