EnableServiceRecovery, RestartService and subsequent failures

1,627 views
Skip to first unread message

Ken Egozi

unread,
Nov 16, 2012, 1:46:39 PM11/16/12
to topshelf...@googlegroups.com
Hi - 
first thing's first - this project is great. Thanks for all the work here!

Now to my problem - I'm trying to get a service installed in a way that subsequent errors will restart the service (first error - restart, second - restart, subsequent - restart).

I tried configuring using c.EnableServiceRecovery ... and then r.RestartService(1) three times, but then the service would not install nor start. only way now is to do a single r.RestartService(1) call, and then manually go to services.msc and set the recovery options.

is there another way or is it simply a bug that I should explore, fix and send pull request?

Dru Sellers

unread,
Nov 16, 2012, 1:48:17 PM11/16/12
to topshelf...@googlegroups.com
I don't think we, yet, have a way to do that. If you can track the registry changes you could probably add a SecondTime and ThirdTime type call to the DSL

-d

Travis Smith

unread,
Nov 16, 2012, 2:06:14 PM11/16/12
to topshelf...@googlegroups.com
We had someone write the code to make these changes, but I'm not sure it actually works. Or it worked on 32bit machines but not 64bit machines. If you feel like digging into it, I'd be happy to help you get started. If it really worked, that would be great. 

-Travis

Chris Patterson

unread,
Nov 16, 2012, 4:17:31 PM11/16/12
to topshelf...@googlegroups.com
It works fine, you just have to set the reset timeout to 0, so that it always resets the restart action after each restart of the service.

Chris Patterson

unread,
Nov 16, 2012, 4:18:01 PM11/16/12
to topshelf...@googlegroups.com
Travis, that was before, the current (3.x) codebase works perfectly when setting the Recovery options.


On Fri, Nov 16, 2012 at 1:06 PM, Travis Smith <tra...@legomaster.net> wrote:

Travis Smith

unread,
Nov 16, 2012, 4:25:04 PM11/16/12
to topshelf...@googlegroups.com
Ohh, I'm behind the times. Excellent. 

-Travis

Ken Egozi

unread,
Nov 17, 2012, 4:00:46 AM11/17/12
to topshelf...@googlegroups.com
not working for me.
I tried setting it with 0, it did set 0 reset time, but in fact the service never restarts after failure now.
I'll try to dig deeper into what's going on here

Stefan Rinkes

unread,
Nov 17, 2012, 2:26:01 PM11/17/12
to topshelf...@googlegroups.com
I would be very interested in a working solution.
Its a topic coming soon on my todo-list :)

Chris Patterson

unread,
Nov 17, 2012, 4:58:29 PM11/17/12
to topshelf...@googlegroups.com
If you configure it manually using the services control manager, does it properly restart? If so, then there is likely some tiny setting that is being left out.

FYI, for a service to be restarted, it has to CRASH (not return a 0 exit code).

Chris Patterson

unread,
Jan 9, 2013, 8:56:39 AM1/9/13
to topshelf...@googlegroups.com
That could be related, the service recovery code is fairly new (based on a contribution) but I don't think it was clear how the service had to exit in order to be restarted by the SCM.


On Wed, Jan 9, 2013 at 4:53 AM, MattiasD <matt...@outlook.com> wrote:
I also can't get the service to restart.
Could it be a missing exit code int the CatchUnhandledException-method in WindowsSercviceHost so the service never actually crashes?
 
Great work with Topshelf btw!

MattiasD

unread,
Jan 9, 2013, 9:16:49 AM1/9/13
to topshelf...@googlegroups.com
The service recovery code registers the windows service correct but when my code throws an unhandled exception Topshelf catches that and stops the service gracefully without setting an error exit code and then the SCM doesn't know that it should restart the service.

Chris Patterson

unread,
Jan 9, 2013, 3:09:14 PM1/9/13
to topshelf...@googlegroups.com
Are you returning the host.Run() exit code as an int from Main() in your service Program.cs?

MattiasD

unread,
Jan 10, 2013, 3:54:01 AM1/10/13
to topshelf...@googlegroups.com
Yes, but it looks like the scm doesn't care about the return code from Main. At first the return code was 0 after an unhandled exception so I added "ExitCode = (int)TopshelfExitCode.AbnormalExit;" in WindowsServiceHost.CatchUnhandledException and recompiled Topshelf. And even with return code 1 the scm won't restart the service.
Reply all
Reply to author
Forward
0 new messages