[Win32utils-devel] Issues with win32-service Daemon

win32utils-devel at rubyforge.org win32utils-devel at rubyforge.org
Mon Apr 12 10:47:58 EDT 2004


> -----Original Message-----
> From: win32utils-devel-bounces at rubyforge.org 
> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of 
> win32utils-devel at rubyforge.org
> Sent: Saturday, April 10, 2004 1:46 AM
> To: win32utils-devel at rubyforge.org
> Subject: Re: [Win32utils-devel] Issues with win32-service Daemon
> 
> 
> Hi Dan,
> 
> 
> > Hi all,
> >
> > I wrote a little echo client to run as a service.  I have a 
> couple of
> > problems with this.   First, any time I try to define anything in
> > "initialize", the service fails to start.  Any idea why?
> >
> > Also, this service runs for a while, then just quits for no reason 
> > that I can see.  The Event Log merely says, "The Abba service 
> > terminated unexpectedly".
> >
> > Any ideas on either issue?
> >
> 1. You can solve the problem by breaking off the relation 
> between Daemon class and Service class. Modify service.c line 1579
>   cDaemon  = rb_define_class_under(mWin32, "Daemon", 
> rb_cService); with
>   cDaemon  = rb_define_class_under(mWin32, "Daemon", rb_cObject);

Perhaps we should do this.  I'm trying to remember if we had a good
reason for making it a subclass of Service.

> 
> 2. Try begin ... rescue for exception handling. You will see 
> what cause the termination.
> 
> Park Heesob
> 
> # myservice.rb
> require "socket"
> require "win32/service"
> include Win32
> 
> class MyDaemon < Daemon
> def initialize
>   @a = "10"
> end
> 
> def service_main
>     begin
>   File.open("c:\\test.log","a+"){ |f| f.puts("service_main 
> entered with
> #{@a}") }
>   s = TCPServer.new(8888)
>   while socket = s.accept
>    rv = socket.gets.chomp
>    File.open("c:\\test.log","a+"){ |f| f.puts "GOT: #{rv}" }
>    socket.puts "Thanks!"
>   end
>   File.open("c:\\test.log","a+") { |f| f.puts("service_main left") }
>   #s.close
>     end
>     rescue StandardError, Interrupt
>         File.open("c:\\test.log","a+") { |f| f.puts("Error: #{$!}") }
>     end
> 
> end
> 
> m = MyDaemon.new
> m.mainloop

Actually it doesn't seem to help - nothing gets logged except in the
Event Log.  It takes about 10-15 minutes for this to happen, btw.  A
little Google searching indicates that the SCM is receiving an
unexpected exit somehow, so I may slap some extra code in to "watch" the
SCM to see what's going on.

Regards,

Dan



More information about the win32utils-devel mailing list