I''m back to getting stuff to run as a Windows service, and am running in to a problem. My service (a Daemon ruby class) installs and starts fine, but when I try to stop it, I get: C:\workspaces\default\tahoe>ruby script\service stop script/service:77:in `stop'': An exception occurred in the service when handling the control request. (Win32::ServiceError) from script/service:77 from script/service:76:in `call'' from script/service:88 Note that I only get this if the service has successfully made it in to service_main - if I stop it before that, it stops OK. I wanted to back up and see if the examples worked OK for me, so I ran daemon_test: C:\build\ruby\extensions\win32-service-0.4.6\examples>ruby daemon_test.rb install VERSION: 0.4.6 installed C:\build\ruby\extensions\win32-service-0.4.6\examples>ruby daemon_test.rb start VERSION: 0.4.6 Ok, started C:\build\ruby\extensions\win32-service-0.4.6\examples>ruby daemon_test.rb stop VERSION: 0.4.6 daemon_test.rb:59:in `stop'': The pipe has been ended. (Win32::ServiceError) from daemon_test.rb:59 Note that you need to wait to attempt the stop until after the service has started writing "service is running" to C:\test.log before it will fail. Any ideas on either of these problems, and/or ways to debug better? I''m running ruby1.8.3p1 compiled locally with MSVC (7, I think), with win32-service-0.4.6 on XP Pro SP2. Thanks, -- Nathaniel Talbott <:((><
Hi Nathaniel,> -----Original Message----- > From: win32utils-devel-bounces@rubyforge.org > [mailto:win32utils-devel-bounces@rubyforge.org] On Behalf Of > Nathaniel Talbott > Sent: Thursday, September 08, 2005 11:54 AM > To: Development and ideas for win32utils projects > Subject: [Win32utils-devel] Stopping services > > > I''m back to getting stuff to run as a Windows service, and am > running in to a problem. My service (a Daemon ruby class) > installs and starts fine, but when I try to stop it, I get: > > C:\workspaces\default\tahoe>ruby script\service stop > script/service:77:in `stop'': An exception occurred in the > service when handling > the control request. (Win32::ServiceError) > from script/service:77 > from script/service:76:in `call'' > from script/service:88 > > Note that I only get this if the service has successfully > made it in to service_main - if I stop it before that, it stops OK.Yes, I had that issue a while back. See http://rubyforge.org/pipermail/win32utils-devel/2004-August/000144.html. It was never resolved, but it seemed to be harmless. Yes, it raised an error, but the service does stop. Not ideal, but liveable. My *guess* is that it has something to do with the fact that win32-service spawns a native thread (in the service_mainloop function) which is, afaik, required. But, that''s a guess. If I''m right, I don''t know that it''s a solveable issue until Ruby 2.0. If I''m wrong, then I''m not sure what the issue is. Any ideas Heesob? Dan
On 9/8/05, Berger, Daniel <Daniel.Berger@qwest.com> wrote:> Hi Nathaniel, > > > I''m back to getting stuff to run as a Windows service, and am > > running in to a problem. My service (a Daemon ruby class) > > installs and starts fine, but when I try to stop it, I get: > > > > C:\workspaces\default\tahoe>ruby script\service stop > > script/service:77:in `stop'': An exception occurred in the > > service when handling > > the control request. (Win32::ServiceError) > > from script/service:77 > > from script/service:76:in `call'' > > from script/service:88 > > > > Note that I only get this if the service has successfully > > made it in to service_main - if I stop it before that, it stops OK. > > Yes, I had that issue a while back. See > http://rubyforge.org/pipermail/win32utils-devel/2004-August/000144.html. > > It was never resolved, but it seemed to be harmless. Yes, it raised an > error, but the service does stop. Not ideal, but liveable.While it does work OK, I''m hesitant to release something that may be managed by other people and tell them, "Oh, the service manager just hangs when you stop it, don''t worry, it really stopped OK." I can hear, "What kind of hacky software is this???" from here :-/.> My *guess* is that it has something to do with the fact that > win32-service spawns a native thread (in the service_mainloop function) > which is, afaik, required. But, that''s a guess. If I''m right, I don''t > know that it''s a solveable issue until Ruby 2.0.Really? Even with your wiz-bang mad C hackery skillz? :-)> If I''m wrong, then I''m not sure what the issue is. Any ideas Heesob?Any other ideas would be greatly appreciated. Thanks, -- Nathaniel Talbott <:((><
On 9/8/05, Berger, Daniel <Daniel.Berger@qwest.com> wrote:> It was never resolved, but it seemed to be harmless. Yes, it raised an > error, but the service does stop. Not ideal, but liveable.FYI, I also can''t seem to get it to call my #service_stop method, which I''m guessing is related. Have you had the same problem? -- Nathaniel Talbott <:((><
> -----Original Message----- > From: win32utils-devel-bounces@rubyforge.org > [mailto:win32utils-devel-bounces@rubyforge.org] On Behalf Of > Nathaniel Talbott > Sent: Friday, September 09, 2005 6:20 AM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Stopping services> > Really? Even with your wiz-bang mad C hackery skillz? :-)My mad C hackery skillz led me to this in the Service_Ctrl function: // Tell service_main thread to stop. if ((dwCtrlCode == SERVICE_CONTROL_STOP) || (dwCtrlCode == SERVICE_CONTROL_SHUTDOWN)) { if (!SetEvent(hStopEvent)) ErrorStopService(); // Raise an error here? } So, if SetEvent (a Windows function) fails, we call ErrorStopService (our function). Looking at ErrorStopService I see this: // If you have threads running, tell them to stop. Something went // wrong, and you need to stop them so you can inform the SCM. SetEvent(hStopEvent); // Stop the service. SetTheServiceStatus(SERVICE_STOPPED, GetLastError(), 0, 0); Looking at SetTheServiceStatus (our function) I see this: // Send status of the service to the Service Controller. if(!SetServiceStatus(ssh, &ss)){ ErrorStopService(); } It almost looks like we could end up with an infinite loop. Is the SCM saving our butt here by just timing out and shutting down the service for us? I''m not sure. I think we need to look more closely at why SetEvent() is failing. Perhaps raising an error is in order. That''s where I''m going to start looking anyway. Regards, Dan
> -----Original Message----- > From: win32utils-devel-bounces@rubyforge.org > [mailto:win32utils-devel-bounces@rubyforge.org] On Behalf Of > Nathaniel Talbott > Sent: Friday, September 09, 2005 7:49 AM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Stopping services > > > On 9/8/05, Berger, Daniel <Daniel.Berger@qwest.com> wrote: > > > It was never resolved, but it seemed to be harmless. Yes, > it raised > > an error, but the service does stop. Not ideal, but liveable. > > FYI, I also can''t seem to get it to call my #service_stop > method, which I''m guessing is related. Have you had the same problem?Upon further review, things seem to be working fine. :/ I installed, ran, and stopped the sample (Abba) service. Here was the log output: service is running as of: Fri Sep 09 10:15:39 Mountain Daylight Time 2005 service is running as of: Fri Sep 09 10:15:42 Mountain Daylight Time 2005 service is running as of: Fri Sep 09 10:15:45 Mountain Daylight Time 2005 stop signal received: Fri Sep 09 10:15:48 Mountain Daylight Time 2005 service is running as of: Fri Sep 09 10:15:48 Mountain Daylight Time 2005 service_main left It didn''t hang when I stopped (which I tried from both the command line and the Services GUI). And, as you can see, it definitely picked up the stop event. What version of Windows and win32-service are you running? And how did you build it? Dan
On 9/9/05, Berger, Daniel <Daniel.Berger@qwest.com> wrote:> Upon further review, things seem to be working fine. :/ > > I installed, ran, and stopped the sample (Abba) service. Here was the > log output: > > service is running as of: Fri Sep 09 10:15:39 Mountain Daylight Time > 2005 > service is running as of: Fri Sep 09 10:15:42 Mountain Daylight Time > 2005 > service is running as of: Fri Sep 09 10:15:45 Mountain Daylight Time > 2005 > stop signal received: Fri Sep 09 10:15:48 Mountain Daylight Time 2005 > service is running as of: Fri Sep 09 10:15:48 Mountain Daylight Time > 2005 > service_main left > > It didn''t hang when I stopped (which I tried from both the command line > and the Services GUI). And, as you can see, it definitely picked up the > stop event. > > What version of Windows and win32-service are you running? And how did > you build it?See my first message... I also tried the sample service, and while it had a different error, it did error, and I never get the "stop signal" in my log. My original message outlines my environment, too - let me know if you need additional info. Thanks, -- Nathaniel Talbott <:((><
On 9/9/05, Nathaniel Talbott <ntalbott@gmail.com> wrote:> My original message outlines my environment, too - let me > know if you need additional info.One bit of clarification as to my environment - I''m building with VS.NET 2003. -- Nathaniel Talbott <:((><
> -----Original Message----- > From: win32utils-devel-bounces@rubyforge.org > [mailto:win32utils-devel-bounces@rubyforge.org] On Behalf Of > Nathaniel Talbott > Sent: Friday, September 09, 2005 12:13 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Stopping services> > What version of Windows and win32-service are you running? And how > > did you build it? > > See my first message... I also tried the sample service, and > while it had a different error, it did error, and I never get > the "stop signal" in my log. My original message outlines my > environment, too - let me know if you need additional info.Sorry, I wasn''t paying attention. :( I''ll try building 1.8.3 at home this weekend and see what happens. Anyone else seeing this behavior? Thanks. Dan
On 9/9/05, Berger, Daniel <Daniel.Berger@qwest.com> wrote:> Sorry, I wasn''t paying attention. :(No problem.> I''ll try building 1.8.3 at home this weekend and see what happens.Thanks a lot for your help... I really, really want to be able to use Ruby for this sort of thing, instead of having to use some sort of service wrapper, and I don''t think I''m the only one. While I like to dis Windows as much as the next guy, good support for it is really valuable to the community. Thanks for all the work you (and the others here) do. Looking forward to hearing what you find out this weekend, -- Nathaniel Talbott <:((><
Nathaniel Talbott wrote:> Thanks for all the work you (and the others here) do. >I am merely an end user of the win32 packages, but I would like to second this thanks! Zach
Nathaniel Talbott wrote:>Thanks a lot for your help... I really, really want to be able to use >Ruby for this sort of thing, instead of having to use some sort of >service wrapper, and I don''t think I''m the only one. While I like to >dis Windows as much as the next guy, good support for it is really >valuable to the community. Thanks for all the work you (and the others >here) do. > >Looking forward to hearing what you find out this weekend, > > > >Alright, I built the latest stable release (10-Sep-2005) on my XP home laptop, ran the "daemon_test.rb" script again, and still had no problems. I can only guess that has something to do with your development environment, unless there''s something specific about 1.8.3p1 causing the issue. You could try the latest stable release and see if that makes a difference. How are your C skills? I think at this point I would try adding some debug code directly in service.c, especially around the SetEvent() calls, to see if that''s the culprit or not. Regards, Dan