Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Matt Silbernagel
RE: upgrade broke win32::service [ reply ]  
2008-10-07 15:52
I'm having a similar problem, but I downloaded the source and installed the demo service with no problem. But when I try to start it I get this error:

VERSION: 0.6.1
C:/Ruby/lib/ruby/gems/1.8/gems/win32-service-0.6.1-x86-mswin32-60/lib/win32/service.rb:700:in `start': The service did not re
spond to the start or control request in a timely fashion. (Win32::Service::Error)
from U:/Projects/labs/labAdmin/examples/demo_daemon_ctl.rb:66


By: Humphrey Drummond
RE: upgrade broke win32::service [ reply ]  
2008-05-28 14:49
Maybe silly but I needed to add
include Win32
for it to recognise the class Daemon
however it is not yet running for me. I am trying to put it some notes together http://rubypane.blogspot.com/2008/05/windows-service-using-win32-service-and.html

By: Daniel Berger
RE: upgrade broke win32::service [ reply ]  
2008-05-17 14:39
Hi Tim,

Do me a favor and download the win32-service source file and try installing and starting the DemoDaemon that you'll find under the 'examples' directory. Please let me know how that goes.

Thanks,

Dan

By: Tim Uckun
RE: upgrade broke win32::service [ reply ]  
2008-05-15 23:20
I am not quite sure what the problem is still. The error message is always the cyrptic and uninformative one I posted earlier.

In order to debug I created a skeleton service (posted below). This service does run but when you go to stop it you get an error message from windows. The service does stop however. If you restart you don't get the error message.

If you leave out the "exit!" the service takes forever to stop but gives no error messages. With the exit! it stops right away and gives the error.

The error from windows is "Could not stop the test_service service on local computer. Error 1067: The process terminated unexpectedly". The event log contains nothing useful.

Here is the code.

begin
logdir = File.expand_path("#{File.dirname(__FILE__)}/../log")
$stdout.reopen(File.open("#{logdir}/stdout.log", "w"))
$stderr.reopen(File.open("#{logdir}/sterr.log", "w"))

require 'win32/service'
require "win32/daemon"
include Win32

class Daemon

def service_stop
exit!
end
def service_main
while running? #state == RUNNING || state == PAUSED || state == IDLE
sleep 60
end #while running
end #service_main

end #class
Daemon.new().mainloop

rescue => e
require 'logger'
logger = Logger.new("#{logdir}/service_error.log" )
msg = e.message + e.backtrace.join("\n")
logger.fatal msg

end



By: Daniel Berger
RE: upgrade broke win32::service [ reply ]  
2008-05-15 15:26
Two things. First, define 'service_stop' and put "exit!" as the method (along with any other cleanup you want).

Second, wrap your service in a begin/rescue and write the error to a file. Be sure to reopen STDERR to the log file first.

HTH,

Dan

By: Tim Uckun
RE: upgrade broke win32::service [ reply ]  
2008-05-15 07:04
That got rid of that error. Now I get a cryptic

in `mainloop': Service_Main thread exited abnormally (Win32::Daemon::Error)


Error. I'll dig a little bit further. It may be in my class someplace.

By: Daniel Berger
RE: upgrade broke win32::service [ reply ]  
2008-05-15 04:45
Oh, wait, I'll bet I know. In 0.5.x both classes were lumped together. In 0.6.x, they're separate files. Add 'require "win32/daemon"' to the top of your service. That should do it.

Regards,

Dan

By: Daniel Berger
RE: upgrade broke win32::service [ reply ]  
2008-05-15 04:19
Does it work if you do Daemon.new.mainloop? Or Daemon.mainloop?

Dan

By: Tim Uckun
upgrade broke win32::service [ reply ]  
2008-05-15 03:36
I have a windows service written in ruby. I have updated my win32 service gem and it no longer works.

In the previous version my class inherited from Win32::Daemon. Apparently that's not there anymore.

I tried just naming my class Daemon like you have in the example but that doesn't work either. It gives me a undefined method `mainloop' for #<Daemon:0x2bece98>

What am I doing wrong?